Can you store an Array in Memcache?
I would like to store;
- A user ID number
- A user's photo URL
- A users name
Together as an array, someone told me you could and then someone told me you couldn't Which is it?
Can you store an Array in Memcache?
I would like to store;
Together as an array, someone told me you could and then someone told me you couldn't Which is it?
You can store almost whatever you want in memcached.
See the documentation of
memcache::set
, which says :So, yes, you can store an array, or even an object if needed :-)
BTW, it's the same with
Memcache::add
andMemcache::replace
max storage size of an item in memcache is 1,048,576 Bytes (1MB), serializing an array does take a bit of space.
if you were to structure your array as simply as:
key being auto generated and value being the user id.
a serialized array of 5000 users numbered 1-5000 using this structure has a string length of 67792 characters, 50000 users produces an array of 777794 characters.
numbering 100000 to 150000 produces a serialized string of 838917 characters.
so at 50k users (as referenced in your previous question), you will likely be under the 1MB limit. if you have a local cache though (APC, etc...), use that instead, or if for any reason do NOT need all the IDs at once, I would highly suggest splitting up the results or simply using the DB.
also think about the data structure you are storing in memcached. If you are using the cache simply to give you a list of primary keys to lookup, do you need the other data?
Yes.
Please see the documentation for very detailed examples.
add change database setting according to ur requirement ,tested code please try