darrynten / any-cache
Adapter designed to add Framework Agnosticism for Caching within PHP Packages.
Installs: 80 092
Dependents: 10
Suggesters: 0
Security: 0
Stars: 8
Watchers: 3
Forks: 2
Open Issues: 9
Requires
- php: ^5.5.9 || ^7.0
Requires (Dev)
- doctrine/cache: ^1.6
- illuminate/cache: ^5.4
- illuminate/contracts: ^5.4
- mockery/mockery: dev-master
- phpunit/phpunit: ~5.0
- symfony/cache: ~3.0
- symfony/dependency-injection: ~2.8|~3.0
- symfony/http-kernel: ~2.8|~3.0
Suggests
- doctrine/cache: Use any Doctrine cache driver for cache
- symfony/cache: Use any Symfony cache driver for cache
This package is auto-updated.
Last update: 2024-11-09 10:52:48 UTC
README
Adapter designed to add Framework Agnosticism for Caching within PHP Packages.
Supports PHP 5.6+
Install
composer require darrynten/any-cache
Goal
Allow package developers to use whichever caching mechanisms are native to whichever framework it is installed in via a simple interface.
Can be passed an artifact, but can also autodetect its host framework.
Passing in takes precedence and allows developers to use a specific framework but with a totally different cache library or configuration.
Details
Package creators can include AnyCache
in their packages and leverage
supported host framework native caching capabilities.
AnyCache
auto-detects its host framework and does not require any
extra configuration, although it also allows passing in a desired cache.
If none is provided or if there is no caching available, then a local
temporary ArrayCache
is created and will be used by default. This is
transient and not persistent.
This allows you to not have any additional caching requirements in your packages while allowing you to leverage whichever caching constructs are already in place.
Supported Frameworks
- Temporary Array (default)
- Laravel
- Symfony
- Doctrine
- Psr6
- CodeIgniter (partially complete)
- ...
Supported Cache Calls
- get ($key, $default)
- set ($key, $value, $time)
- has ($key)
- pull ($key)
- forever ($key, $value)
- ...
Provides
Create a new instance.
use DarrynTen\AnyCache; $this->cache = new AnyCache()
Call
$key = 'foo'; $value = 'bar'; $time = 60; // Set a value $this->cache()->set($key, $value, $time); // Get a cached value $result = $this->cache()->get($key); // Check if a key exists if ($this->cache->has($key)) { // } // Get and unset $result = $this->cache()->pull($key);
Notes
The CodeIgniter support is not complete, and it does not auto-detect this framework at this time.
Missing Tests
The Laravel tests are not 100% complete, there is an issue with
testing the Cache Facade on the get
method.
The factory does not have unit test coverage at this point in time.
The main class is also not tested yet.
Acknowledgments
- Marcel Pociot and his Botman Project for the original idea and implementation.
- Alexander Marinov for his amazing skills.