Giter Site home page Giter Site logo

any-cache's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.