Cache Implementation

Corma requires a Cache that extends CacheProvider from DoctrinCache. If you don't provide a cache an in memory ArrayCache is used. Using an external cache (i.e Redis or Memcache) and combining it with an ArrayCache will provide the best performance for most use cases. This is done in the doctrine caching classes via a ChainCache.

$caches = [new ArrayCache()];
$redis = new \Redis();
$redis->connect($host);
$redisCache = new RedisCache();
$redisCache->setRedis($redis);
$caches[] = $redisCache;
$chainCache = new ChainCache($caches);

Objects cached by id

The default repository implementation uses a identity map pattern to store objects by id once they are loaded by id. This reduces both cache and database accesses. This does not use the cache, just a ordinary php array.

Using Cache

By default Corma will only use the cache to store table metadata only. The cache is injected into all your repositories, so you can use it to do your own caching. In addition we provide two base repository classes to make it easy to cache your objects and reduce the number of database queries.

CachingObjectRepository

This class caches individual objects by id, by default for 24 hours. The find() and findByIds() method both check cache before querying the database.

ReadOnlyObjectRepository

Repository that aggressively caches its results (in a single cache entry) and does not permit saving or deleting. The find(), findByIds(), and findAll() methods operate exclusively from cache once the cache is warm. This class is not meant for large tables as the entire table is loaded into memory and cache.