Download the PHP package ruvents/spiral-cache without Composer
On this page you can find all versions of the php package ruvents/spiral-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ruvents/spiral-cache
More information about ruvents/spiral-cache
Files in ruvents/spiral-cache
Package spiral-cache
Short Description PSR-{6,16} compatible cache integration
License MIT
Informations about the package spiral-cache
Spiral cache
This package integrates PSR-6 and PSR-16 compatible cache implementations (mostly Symfony one) into Spiral application. As a bonus it provides convenient caching solution for HTTP responses.
Installation
psr/simple-cache
is optional, you can only use PSR-6 compliant cache.
symfony/cache
is optional, you can use any PSR-6 implementation of your
choice.
Then add CacheBootloader
to your App.php
:
Configuration
Put the following code into file app/config/cache.php
:
Default pool must be created in order for package to function properly.
Use
Manually
After configuration you should be able to inject created cache pool into your code by its name:
If symfony/cache
is installed you can upgrade PSR-6 cache implementation to
PSR-16 by specifying CacheInterface
:
If symfony/cache
is installed you can inject
its implementation of cache:
If symfony/cache
is installed you can inject tag-aware cache:
With #[Cached] attribute
You can use #[Cached]
attribute to remove caching code from HTTP action. You'll
need to install Ruvents\SpiralCache\CacheInterceptor
in order to have this
attribute recognized. See
related documentation
for installation details.
Here is an example on how to cache HTTP response for a given action:
Method's class name, method's name and request URI are all used to automatically
generate cache key. To implement custom key generation logic specify key
in
attribute:
If you want to apply caching conditionally specify callable array in if
key:
If symfony/cache
is installed and TagAwareCacheInterface
is used as
controllerPool
you can selectively clear groups of cache items by specifying
tags
:
All versions of spiral-cache with dependencies
psr/cache Version ^1.0
psr/http-message Version ^1.0.1
spiral/framework Version ^2.8