PHPackages                             germania-kg/cachecallable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. germania-kg/cachecallable

ActiveLibrary[Caching](/categories/caching)

germania-kg/cachecallable
=========================

Callable convenience wrapper around PSR-6 Cache Item Pools: Seamlessly create, return, and store your data.

2.2.0(3y ago)01.8k[1 issues](https://github.com/GermaniaKG/CacheCallable/issues)2MITPHPPHP ^7.4|^8.0CI failing

Since Oct 4Pushed 3y ago3 watchersCompare

[ Source](https://github.com/GermaniaKG/CacheCallable)[ Packagist](https://packagist.org/packages/germania-kg/cachecallable)[ RSS](/packages/germania-kg-cachecallable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (9)Versions (36)Used By (2)

Germania KG · CacheCallable
===========================

[](#germania-kg--cachecallable)

[![Packagist](https://camo.githubusercontent.com/ed515de3ed07fd9041726798ca7b78621f3343fe250b565915728a49e3a74f28/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6765726d616e69612d6b672f636163686563616c6c61626c652e7376673f7374796c653d666c6174)](https://packagist.org/packages/germania-kg/cachecallable)[![PHP version](https://camo.githubusercontent.com/57f37bc314892a699fb4fd7d00173a8bf4269c990ffa59771230866f0d96e053/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6765726d616e69612d6b672f636163686563616c6c61626c652e737667)](https://packagist.org/packages/germania-kg/cachecallable)[![Tests](https://github.com/GermaniaKG/CacheCallable/actions/workflows/tests.yml/badge.svg)](https://github.com/GermaniaKG/CacheCallable/actions/workflows/tests.yml)

**Callable convenience wrapper around PSR-6 [Cache Item Pools](http://www.php-fig.org/psr/psr-6/#cacheitempoolinterface): Seamlessly creates, returns, and stores your data.**

Caching business is pretty much always similar and can be outlined like this:

1. **Is caching enabled at all?** If not, delete any according older entry first.
    Create and return fresh content anyway, ending up here.
2. **Does a given item exist?** If so, return item content;
    Otherwise, create, store and return content.

**The *CacheCallable* class reduces these steps to a handy and customizable Callable.**

Installation with Composer
--------------------------

[](#installation-with-composer)

```
$ composer require germania-kg/cachecallable
```

Example
-------

[](#example)

Although this example uses [phpfastcache](http://www.phpfastcache.com/), you should be able to pass in any [Cache Item Pool](http://www.php-fig.org/psr/psr-6/#cacheitempoolinterface). Use your favourite [PSR-3 Logger](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#3-psrlogloggerinterface); this example will use the well-known [Monolog](https://github.com/Seldaek/monolog).

```
