thecodingmachine/symfony-cache-universal-module

Cross-framework module for Symfony cache

dev-master / 1.0.x-dev 2018-08-19 13:31 UTC

This package is auto-updated.

Last update: 2024-11-07 01:08:33 UTC


README

Latest Stable Version Latest Unstable Version License Build Status Coverage Status

Symfony cache universal module

This package integrates the Symfoncy Cache component in any container-interop compatible framework/container.

Installation

$ composer require thecodingmachine/symfony-cache-universal-module

Once installed, you need to register the TheCodingMachine\SymfonyCacheServiceProvider into your container.

If your container supports thecodingmachine/discovery integration, you have nothing to do. Otherwise, refer to your framework or container's documentation to learn how to register service providers.

Introduction

This service provider is meant to create both PSR-16 caches Psr\SimpleCache\CacheInterface and PSR-6 cache pools Psr\Cache\CacheItemPoolInterface instance.

Out of the box, the instance should be usable with sensible defaults. We tried to keep the defaults usable for most of the developer, while still providing best performances for the server:

  • the provided caches are made of chainable caches
  • the first level is an ArrayCache (in-memory) for fast access to already fetched values
  • the second level is an APCu cache, with a PhpFilesCache fallback if the APCu extension is not available.

Note: the Symfony cache component provides a lot of adapters for a lot of platforms. This service provider does not attempt to map all the caches provided but instead focuses on sane defaults.

PSR-16 Usage

use Psr\SimpleCache\CacheInterface

$cache = $container->get(CacheInterface::class);
echo $cachePool->get('my_cached_value');

PSR-6 Usage

use Psr\Cache\CacheItemPoolInterface

$cachePool = $container->get(CacheItemPoolInterface::class);
echo $cachePool->getItem('my_cached_value')->get();

Expected values / services

This service provider expects the following configuration / services to be available:

Provided services

This service provider provides the following services:

Project template courtesy of thecodingmachine/service-provider-template