Cache guide
The Cache module provides your Cherrycake application with a standardized interface to implement caching and shared memory mechanisms into your App by connecting to multiple external cache providers.
To use cache in your application, you must first define a cache provider. Each cache provider connects your app with a different cache mechanism or server, that means your app can make use of different caches at the same time.
Cache providers are configured in the Cache configuration file
/config/Cache.config.php
. For example, if you want to use a simple but fast APCu cache provider, your Cache configuration file would look like this:<?php
namespace Cherrycake;
$CacheConfig = [
"providers" => [
"fast" => [
"providerClassName" => "CacheProviderApcu"
]
]
];
Note we called our cache providerfast
You can configure more than one cache providers. For example, let's add a Redis cache provider too, called
huge
:<?php
namespace Cherrycake;
$CacheConfig = [
"providers" => [
"fast" => [
"providerClassName" => "CacheProviderApcu"
],
"huge" => [
"providerClassName" => "CacheProviderRedis",
"config" => [
"scheme" => "tcp",
"host" => "localhost"
"port" => 6379,
"database" => 0,
"prefix" => "CherrycakeApp:"
]
]
]
];
Since some functionalities of Cherrycake make use of caching mechanisms, there is a default cache provider calledengine
that uses an APCu cache provider. This provider is always defined, no matter what you setup in yourCache.config.php
file.
However, you can not rely on a cache or shared memory system as a persistent way of storing information. Generally, cached objects are deleted when the server restarts, when it runs out of memory, or if it implements certain cache eviction policies, like removing all cached objects that are too old, or that haven't been accessed too much.
This methods are specially suited for high performance operations like the storage of events in a high traffic scenario, or the intermediate storage of data that needs to be accessed extremely fast, lots of times per second.
Last modified 3yr ago