emag / cache-bundle
CacheBundle by eMAGTechLabs
Installs: 16 484
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 15
Forks: 5
Open Issues: 4
Requires
- php: >=7.0
- doctrine/annotations: ~1.3
- ocramius/proxy-manager: 2.*
- psr/cache: 1.0.*
- psr/container: ^1.0
- psr/log: 1.*
- symfony/dependency-injection: >3.3
Requires (Dev)
- phing/phing: @stable
- phpmd/phpmd: @stable
- phpunit/phpunit: 5.*
- satooshi/php-coveralls: ~1.0
- sebastian/phpcpd: ~2
- squizlabs/php_codesniffer: 2.*
- symfony/cache: 3.*
- symfony/framework-bundle: @stable
- symfony/http-kernel: 3.*
- symfony/monolog-bundle: @stable
Suggests
- symfony/cache: 3.*
README
Installation
In order to have caching on methods you need to install it using composer:
- Add requirement:
$ composer require emag/cache-bundle
- Add to your app/AppKernel.php
class AppKernel extends Kernel { public function registerBundles() { $bundles = [ //... new Emag\CacheBundle\EmagCacheBundle(), //... ]; //... } //.... }
- Configure the bundle required info
You have to configure the name of the service that is PSR6 compliant, that means it will have to implement Psr\Cache\CacheItemPoolInterface
:
# app/config/services.yml services: cache.array: class: Symfony\Component\Cache\Adapter\ArrayAdapter cache.redis: class: Symfony\Component\Cache\Adapter\RedisAdapter arguments: ['@predis']
#app/config/config.yml # eMAG CachingBundle emag_cache: provider: cache.redis ignore_namespaces: - 'Symfony\\' - 'Doctrine\\' - 'Twig_' - 'Monolog\\' - 'Swift_' - 'Sensio\\Bundle\\'
How to use
Add @Cache annotation to the methods you want to be cached:
use Emag\CacheBundle\Annotation\Cache; /** * @Cache(cache="<put your prefix>", [key="<name of argument to include in cache key separated by comma>", [ttl=600, [reset=true ]]]) */
Here is an example from a service:
namespace AppCacheBundle\Service; use Emag\CacheBundle\Annotation\Cache; class AppService { /** * @Cache(cache="app_high_cpu", ttl=60) * * @return int */ public function getHighCPUOperation() { // 'Simulate a time consuming operation'; sleep(10); return 20; } }
Want to contribute?
Submit a PR and join the fun.
Enjoy!