[ Web Proxy ]
URL:
Viewing: https://docs.sonsofphp.com/components/cache [Back]  [Original]

Cache | Sons of PHP
[] []
[] []
On this page
For the complete documentation index, see llms.txt. This page is also available as Markdown.
Copy
On this page
  1. Components

Cache

Installation

Copy
composer require sonsofphp/cache

PSR-16 - Simple Cache

To add support for PSR-16 Simple Cache, require the PSR.

Copy
composer require psr/simple-cache

Usage

Copy
<?php

use SonsOfPHP\Component\Cache\Adapter\ApcuAdapter;

$pool = new ApcuAdapter();

All Adapters implement Psr\Cache\CacheItemPoolInterface

PSR-16 Simple Cache Wrapper

Copy
<?php

use SonsOfPHP\Component\Cache\Adapter\ApcuAdapter;
use SonsOfPHP\Component\Cache\SimpleCache;

$pool = new ApcuAdapter();
$cache = new SimpleCache($pool);

SimpleCache implements Psr\SimpleCache\CacheInterface.

Setting up a multi layer cache

The ChainAdapter will read from all pools and return the first result it finds. So in the above example, if the cache item is not found in ArrayAdapter, it will look for it in the ApcuAdapter pool.

The ChainAdapter will also write to and delete from all pools.

Last updated 1 year ago


Web Proxy Viewer  |  New URL  |  Original Page