The CakePHP framework has excellent support for caching and can be easily used with MemCachier as the provider. To setup CakePHP with MemCachier, you’ll need to edit the file
app/Config/bootstrap.php and add the following lines:
Cache::config('default', array( 'engine' => 'Memcached', 'prefix' => 'mc_', 'duration' => '+7 days', 'compress' => false, 'persistent' => 'memcachier', 'servers' => explode(',', getenv('MEMCACHIER_SERVERS')), 'login' => getenv('MEMCACHIER_USERNAME'), 'password' => getenv('MEMCACHIER_PASSWORD'), 'serialize' => 'php' ));
The values for
MEMCACHIER_PASSWORD are listed on your cache overview page. Make sure to add them to your environment.
After that, you should be able to use caching throughout your application like so:
The above will fetch the value associated with the key
newest_posts from the cache if it exists. Otherwise, it will execute the function and SQL query, storing the result in the cache using the
You can find much more information on how to use caching with CakePHP here.