nicholasruunu / adapter-bundle

A Symfony bundle to register adapters as services

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adapter Bundle

Build Status

This bundle helps you configurate and register PSR-6 cache services.

To Install

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

composer require cache/adapter-bundle

Add the bundle to app/AppKernel.php

$bundles(
    // ...
    new Cache\AdapterBundle\CacheAdapterBundle(),
    // ...
);

Configuration

cache_adapter:
  providers:
    acme_memcached:
      factory: cache.factory.memcached
      options: 
        persistent: true # Boolean or persistent_id
        namespace: mc
        hosts:
          - { host: localhost, port: 11211 }      

Usage

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

cache_adapter:
  providers:
    acme_redis:
      factory: cache.factory.redis

Use the new service as any PSR-6 cache.

/** @var CacheItemPoolInterface $cache */
$cache = $this->container->get('cache.provider.acme_redis');
// 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);

About

A Symfony bundle to register adapters as services

License:MIT License


Languages

Language:PHP 100.0%