Skip to content

Latest commit

 

History

History
116 lines (78 loc) · 2.85 KB

README.md

File metadata and controls

116 lines (78 loc) · 2.85 KB

any-cache

Travis Build Status StyleCI Status codecov Packagist Version MIT License

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