I use Php memcache on PHP Version 5.2.4-2ubuntu5.10 Below you can find the info from phpinfo.
When I use key larger than 250 characters memcache returns true on $memcache->set and false on $memcache->get .
Any idea how to set it to work normally (truncate key at 250 chars)?
If not – what would be the easiest way to override memcache across all my code to log the calls and know where I should change the key?
Thanks
memcache support enabled Active persistent connections 0 Revision $Revision: 1.86 $ Directive Local Value Master Value memcache.allow_failover 1 1 memcache.chunk_size 8192 8192 memcache.default_port 11211 11211 memcache.hash_function crc32 crc32 memcache.hash_strategy standard standard memcache.max_failover_attempts 20 20
The maximum size is indeed 250 (see here).
You shouldn’t truncate the keys, as it can map keys that were different to the same value (same for md5, though it’s highly unlikely to happen by accident).
If you want to detect the cases where it’s happening and since you’re using the OOP interface, you can decorate the memcache object, overriding
setorget(or both) to throw an exception or an error when it finds a long key.With only inheritance (no decoration), you can do