Skip to content

vegagame/simple-cache

 
 

Repository files navigation

Build Status Coverage Status Scrutinizer Code Quality Codacy Badge SensioLabsInsight Reference Status Dependency Status Total Downloads License

Simple Cache Class

This is a simple Cache Abstraction Layer for PHP >= 5.3 that provides a simple interaction with your cache-server. You can define the Adapter / Serializer in the "constructor" or the class will auto-detect you server-cache in this order:

  1. Memcached / Memcache
  2. Redis
  3. Xcache
  4. APC / APCu
  5. static array

##Get "Simple Cache" You can download it from here, or require it using composer.

{
    "require": {
		"voku/simple-cache": "2.*",
		"predis/predis": "1.*"
	}
}

##Install via "composer require"

composer require voku/simple-cache

##Quick Start

    require_once 'composer/autoload.php';

    $cache = new \voku\cache\Cache();
    
    // example
    // $cache = \voku\cache\Cache();
    // $cache->setItem('foo', 'bar');
    // $bar = $cache->getItem('foo');

##Usage

function test() {
  $cache = \voku\cache\Cache();
  
  if (
    $cache->getCacheIsReady() === true
    &&
    $cache->existsItem('foo')
  ) {
    return $cache->getItem('foo');
  } else {
    $bar = someSpecialFunctionsWithAReturnValue();
    $cache->setItem('foo', $bar);
    return $bar;
}

##No-Cache for the admin or a specific ip-address

If you use the parameter "$checkForUser" (true) from the constructor, then the cache isn't used for the admin-session. You can also overwrite the check for the user, if you add a global function named "checkForDev()".

About

Simple Cache Abstraction Layer for PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%