cache/doctrine-adapter-bundle

This package is abandoned and no longer maintained. The author suggests using the cache/adapter-bundle package instead.

A bundle that registers Doctrine cache implementations as Symfony services supporting PSR-6 and tagging

0.2.0 2016-01-02 22:47 UTC

This package is auto-updated.

Last update: 2019-02-20 19:26:42 UTC


README

Doctrine Adapter Bundle

Build Status SensioLabsInsight

This bundle helps you configurate and register PSR-6 cache services. The bundle uses Doctrine as cache implementation with help from DoctrineAdapter to make it PSR-6 complient.

To Install

Run the following in your project root, assuming you have composer set up for your project

composer require cache/doctrine-adapter-bundle

Add the bundle to app/AppKernel.php

$bundles(
    // ...
    new Cache\Adapter\DoctrineAdapterBundle\DoctrineAdapterBundle(),
    // ...
);

Configuration

cache_adapter_doctrine:
  providers:
    acme_memcached:
      type: memcached
      persistent: true # Boolean or persistent_id
      namespace: mc
      hosts:
        - { host: localhost, port: 11211 }
    acme_redis:
      type: redis
      hosts:
        main:
          host: 127.0.0.1
          port: 6379
    acme_file_system_cache:
      type: file_system
      extension: '.fsc'
      directory: '%kernel.root_dir%/var/storage/fs_cache/'
    acme_php_file_cache:
      type: php_file
      extension: '.cache'
      directory: '%kernel.root_dir%/var/storage/'
    acme_array_cache:
      type: array
    acme_apc_cache:
      type: apc
      namespace: my_ns

Usage

When using a configuration like below, you will get a service with the id cache.provider.acme_apc_cache.

cache_adapter_doctrine:
  providers:
    acme_apc_cache:
      type: apc
      namespace: my_ns

Use the new service as any PSR-6 cache.

/** @var CacheItemPoolInterface $cache */
$cache = $this->container->get('cache.provider.acme_apc_cache');
// Or
$cache = $this->container->get('cache'); // This is either the `default` provider, or the first provider in the config

/** @var CacheItemInterface $item */
$item = $cache->getItem('cache-key');
$item->set('foobar');
$item->expiresAfter(3600);
$cache->save($item);