# Nettrine Cache

Doctrine/Cache for Nette Framework.

# Content

# Setup

Install package

composer require nettrine/cache
1

Register extension

extensions:
  nettrine.cache: Nettrine\Cache\DI\CacheExtension
1
2

# Configuration

Schema definition

nettrine.cache:
 driver: <class|service>
1
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

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.

  • Doctrine\Common\Cache\ApcuCache
  • Doctrine\Common\Cache\ArrayCache
  • Doctrine\Common\Cache\ChainCache
  • Doctrine\Common\Cache\CouchbaseBucketCache
  • Doctrine\Common\Cache\FilesystemCache
  • Doctrine\Common\Cache\MemcachedCache
  • Doctrine\Common\Cache\MongoDBCache
  • Doctrine\Common\Cache\PhpFileCache
  • Doctrine\Common\Cache\PredisCache
  • Doctrine\Common\Cache\RedisCache
  • Doctrine\Common\Cache\SQLite3Cache
  • Doctrine\Common\Cache\VoidCache
  • Doctrine\Common\Cache\WinCacheCache
  • Doctrine\Common\Cache\ZendDataCache

# Usage

You can count on Nette Dependency Injection.

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

Register reader MyWorker under services in NEON file.

services:
  - MyWorker
1
2

# Examples

You can find more examples in planette playground repository.