Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you store a PHP Array in Memcache?

Tags:

php

memcached

Can you store an Array in Memcache?

I would like to store;

  1. A user ID number
  2. A user's photo URL
  3. A users name

Together as an array, someone told me you could and then someone told me you couldn't Which is it?

like image 614
JasonDavis Avatar asked Jul 29 '09 22:07

JasonDavis


People also ask

Can Memcached store objects?

Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.

What does memcached do in PHP?

Memcached puts often-used data in RAM, allowing it to be accessed a lot faster. Caching with Memcached works like this: A web browser requests a page, and the server runs PHP code to build it. PHP asks Memcached for the page's data via a Memcached extension.

How enable memcache in PHP INI?

To enable the PHP memcache extensions, build PHP using the --enable-memcache option to configure when building from source. On Debian-based distributions, use the php-memcache package. To set global runtime configuration options, specify the configuration option values within your php. ini file.


1 Answers

Yes.

Memcache::set('someKey', array(
    'user_id' => 1,
    'url' => 'http://',
    'name' => 'Dave'
));

Please see the documentation for very detailed examples.

like image 156
hobodave Avatar answered Oct 15 '22 03:10

hobodave