Contributte Doctrine-cache
Doctrine/Cache (opens new window) for Nette Framework.
# Content
# Setup
Install package
composer require nettrine/cache
1
Register extension
extensions:
nettrine.cache: Nettrine\Cache\DI\CacheExtension
1
2
2
# Configuration
Schema definition
nettrine.cache:
driver: <class|service>
1
2
2
Under the hood
The extension will try to choose a cache driver automatically but you may need to specify one.
PhpFileCache and eventually ApcuCache are the automatically chosen by default. Override it
using the driver key.
nettrine.cache:
driver: Doctrine\Common\Cache\ArrayCache()
1
2
2
ArrayCache is preferred for development, as it offers much better performance than VoidCache - which might be useful for test environments.
Doctrine provides many drivers, see more at doctrine/cache documentation (opens new window).
Doctrine\Common\Cache\ApcuCacheDoctrine\Common\Cache\ArrayCacheDoctrine\Common\Cache\ChainCacheDoctrine\Common\Cache\CouchbaseBucketCacheDoctrine\Common\Cache\FilesystemCacheDoctrine\Common\Cache\MemcachedCacheDoctrine\Common\Cache\MongoDBCacheDoctrine\Common\Cache\PhpFileCacheDoctrine\Common\Cache\PredisCacheDoctrine\Common\Cache\RedisCacheDoctrine\Common\Cache\SQLite3CacheDoctrine\Common\Cache\VoidCacheDoctrine\Common\Cache\WinCacheCacheDoctrine\Common\Cache\ZendDataCache
# Usage
You can count on Nette Dependency Injection (opens new window).
use Doctrine\Common\Cache\Cache;
class MyWorker {
/** @var Cache */
private $cache;
public function __construct(Cache $cache) {
$this->cache = $cache;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
Register reader MyWorker under services in NEON file.
services:
- MyWorker
1
2
2
# Examples
- https://github.com/contributte/playground (opens new window) (playground)
- https://contributte.org/examples.html (opens new window) (more examples)