2017 © Pedro Peláez
 

library simple-cache

Simple Cache library

image

voku/simple-cache

Simple Cache library

  • Tuesday, June 12, 2018
  • by voku
  • Repository
  • 4 Watchers
  • 7 Stars
  • 23,490 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 42 Versions
  • 3 % Grown

The README.md

Build Status FOSSA Status Coverage Status Scrutinizer Code Quality Codacy Badge Latest Stable Version Total Downloads License Donate to this project using Paypal Donate to this project using Patreon, (*1)

:zap: Simple Cache Class

This is a simple Cache Abstraction Layer for PHP >= 7.0 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:, (*2)

  1. Memcached / Memcache
  2. Redis
  3. Xcache
  4. APC / APCu
  5. OpCache (via PHP-files)
  6. Static-PHP-Cache

Get "Simple Cache"

You can download it from here, or require it using composer., (*3)

{
  "require": {
    "voku/simple-cache": "4.*"
  }
}

Install via "composer require"

composer require voku/simple-cache

Quick Start

use voku\cache\Cache;

require_once 'composer/autoload.php';

$cache = new Cache();
$ttl = 3600; // 60s * 60 = 1h
$cache->setItem('foo', 'bar', $ttl);
$bar = $cache->getItem('foo');

Usage

use voku\cache\Cache;

$cache = new Cache();

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

If you have an heavy task e.g. a really-big-loop, then you can also use static-cache. But keep in mind, that this will be stored into PHP (it needs more memory)., (*4)

use voku\cache\Cache;

$cache = new Cache();

if ($cache->getCacheIsReady() === true && $cache->existsItem('foo')) {
  for ($i = 0; $i <= 100000; $i++) {
    echo $this->cache->getItem('foo', 3); // use also static-php-cache, when we hit the cache 3-times
  }
  return $cache->getItem('foo');
} else {
  $bar = someSpecialFunctionsWithAReturnValue();
  $cache->setItem('foo', $bar);
  return $bar;
}

PS: By default, the static cache is also used by >= 10 cache hits. But you can configure this behavior via $cache->setStaticCacheHitCounter(INT)., (*5)

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

If you use the parameter "$checkForUser" (=== true) in the constructor, then the cache isn't used for the admin-session., (*6)

-> You can also overwrite the check for the user, if you add a global function named "checkForDev()"., (*7)

Overwrite the auto-connection option

You can overwrite the cache auto-detect via "CacheAdapterAutoManager" and the "$cacheAdapterManagerForAutoConnect" option in the "Cache"-constructor. Additional you can also activate the "$cacheAdapterManagerForAutoConnectOverwrite" option in the "Cache"-constructor, so that you can implement your own cache auto-detect logic., (*8)


$cacheManager = new \voku\cache\CacheAdapterAutoManager(); // 1. check for "APCu" support first $cacheManager->addAdapter( \voku\cache\AdapterApcu::class ); // 2. check for "APC" support $cacheManager->addAdapter( \voku\cache\AdapterApcu::class ); // 3. try "OpCache"-Cache $cacheManager->addAdapter( \voku\cache\AdapterOpCache::class, static function () { $cacheDir = \realpath(\sys_get_temp_dir()) . '/simple_php_cache_opcache'; return $cacheDir; } ); // 4. try "File"-Cache $cacheManager->addAdapter( \voku\cache\AdapterFileSimple::class, static function () { $cacheDir = \realpath(\sys_get_temp_dir()) . '/simple_php_cache_file'; return $cacheDir; } ); // 5. use Memory Cache as final fallback $cacheManager->addAdapter( \voku\cache\AdapterArray::class ); $cache = new \voku\cache\CachePsr16( null, // use auto-detection null, // use auto-detection false, // do not check for usage true, // enable the cache false, // do not check for admin session false, // do not check for dev false, // do not check for admin session false, // do not check for server vs. client ip '', // do not use "_GET"-parameter for disabling $cacheManager, // new auto-detection logic true // overwrite the auto-detection logic );

Support

For support and donations please visit Github | Issues | PayPal | Patreon., (*9)

For status updates and release announcements please visit Releases | Twitter | Patreon., (*10)

For professional support please contact me., (*11)

Thanks

  • Thanks to GitHub (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc.
  • Thanks to IntelliJ as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
  • Thanks to Travis CI for being the most awesome, easiest continous integration tool out there!
  • Thanks to StyleCI for the simple but powerfull code style check.
  • Thanks to PHPStan && Psalm for relly great Static analysis tools and for discover bugs in the code!

License

FOSSA Status, (*12)

The Versions

12/06 2018

dev-master

9999999-dev https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

 

The Development Requires

cache php caching simple cache

07/01 2018

3.1.1

3.1.1.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

 

The Development Requires

cache php caching simple cache

07/01 2018

3.1.0

3.1.0.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

 

The Development Requires

cache php caching simple cache

14/12 2017

3.0.2

3.0.2.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

 

The Development Requires

cache php caching simple cache

01/12 2017

3.0.1

3.0.1.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

 

The Development Requires

cache php caching simple cache

25/11 2017

3.0.0

3.0.0.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

 

The Development Requires

cache php caching simple cache

06/10 2017

2.4.0

2.4.0.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

 

The Development Requires

cache php caching simple cache

29/07 2017

2.3.5

2.3.5.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

26/07 2017

2.3.4

2.3.4.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

15/03 2017

2.3.3

2.3.3.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

15/03 2017

2.3.2

2.3.2.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

15/03 2017

2.3.1

2.3.1.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

15/03 2017

2.3.0

2.3.0.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

13/03 2017

2.2.0

2.2.0.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

29/09 2016

2.1.1

2.1.1.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

29/08 2016

2.1.0

2.1.0.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

12/07 2016

2.0.13

2.0.13.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

30/06 2016

2.0.12

2.0.12.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

27/06 2016

2.0.11

2.0.11.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

27/06 2016

2.0.10

2.0.10.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

09/06 2016

2.0.9

2.0.9.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

07/06 2016

2.0.8

2.0.8.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

30/03 2016

2.0.7

2.0.7.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

22/10 2015

2.0.6

2.0.6.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

16/10 2015

2.0.5

2.0.5.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

20/08 2015

2.0.4

2.0.4.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

13/08 2015

2.0.3

2.0.3.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

24/07 2015

2.0.2

2.0.2.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

20/07 2015

2.0.1

2.0.1.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

07/07 2015

2.0

2.0.0.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

06/03 2015

1.1.2

1.1.2.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

 

The Development Requires

cache php caching simple cache

20/02 2015

1.1.1

1.1.1.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

 

The Development Requires

cache php caching simple cache

10/02 2015

1.1.0

1.1.0.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

 

The Development Requires

cache php caching simple cache

28/01 2015

1.0.6.1

1.0.6.1 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

 

The Development Requires

cache php caching simple cache

28/01 2015

1.0.6

1.0.6.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

 

The Development Requires

cache php caching simple cache

26/01 2015

1.0.5

1.0.5.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

 

The Development Requires

cache php caching simple cache

26/01 2015

1.0.4.1

1.0.4.1 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

 

The Development Requires

cache php caching simple cache

26/01 2015

1.0.4

1.0.4.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

 

The Development Requires

cache php caching simple cache

26/01 2015

1.0.3

1.0.3.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

 

The Development Requires

cache php caching simple cache

26/01 2015

1.0.2

1.0.2.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

 

The Development Requires

cache php caching simple cache

26/01 2015

1.0.1

1.0.1.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache

26/01 2015

1.0.0

1.0.0.0 https://github.com/voku/simple-cache

Simple Cache library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache php caching simple cache