Integration of Doctrine Cache for Nette Framework.
Install package using composer.
composer require nettrine/cache
Register prepared compiler extension in your config.neon
file.
extensions:
nettrine.cache: Nettrine\Cache\DI\CacheExtension
nettrine.cache:
driver: Symfony\Component\Cache\Adapter\FilesystemAdapter(%tempDir%/cache/nettrine-cache)
nettrine.cache:
driver: <class|service>
Warning
Cache adapter must implement Psr\Cache\CacheItemPoolInterface
interface.
Use any PSR-6 + PSR-16 compatible cache library like symfony/cache
or nette/caching
.
In the simplest case, you can define only adapter
.
nettrine.cache:
# Create cache manually
adapter: App\CacheService(%tempDir%/cache/orm)
# Use registered cache service
adapter: @cacheService
Important
You should always use cache for production environment. It can significantly improve performance of your application. Pick the right cache adapter for your needs. For example from symfony/cache:
FilesystemAdapter
- if you want to cache data on diskArrayAdapter
- if you want to cache data in memoryApcuAdapter
- if you want to cache data in memory and share it between requestsRedisAdapter
- if you want to cache data in memory and share it between requests and serversChainAdapter
- if you want to cache data in multiple storages
The extension will automatically guess the best cache adapter for you.
FilesystemAdapter
- if you havetempDir
definedArrayAdapter
- if you are in CLI modeApcuAdapter
- if you haveapcu
extension enabled- defined - if you have defined
adapter
in configuration
There is no need to use cache directly. It is used by other packages like:
Tip
Take a look at more examples in contributte/doctrine.