2017 © Pedro PelĂĄez
 

library php-cache

Minimal caching library

image

emilio/php-cache

Minimal caching library

  • Saturday, March 11, 2017
  • by ecoal95
  • Repository
  • 2 Watchers
  • 9 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 9 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

PHP filesystem backed cache

This class provides an easy fs-backed cache., (*1)

Read more (es) | Contributors, (*2)

Starting

You can see an easy example in the examples/ dir., (*3)

You can also install this package with composer., (*4)

Configuration

There are two main options: cache_path y expires., (*5)

  • cache_path is the directory where cache will be stored. It's a relative directory by default (cache), but it's recommendable to re-configure it.
  • expires is the cache expiration time in minutes.

Important: cache_path should be writable (that's obvious), but if it's public in the server, which is not recommended, you should forbid access to it., (*6)

A way to do it for Apache is having a .htaccess as follows in the cache dir:, (*7)

deny from all

Usage

To store any data type you should use the put method using an identifier, and the value., (*8)

Cache::put('key', 'value');

Retrieving data

To get data stored in the cache you should use:, (*9)

Cache::get('key');

If the item is not found, or it's expired, it will return null., (*10)

Raw data

You can store and retrieve raw data, to prevent decoding and encoding overhead., (*11)

You should specify it's raw data in both put() and get(), as follows:, (*12)

Cache::put($key, $big_chunk_of_data, true);
// ...
Cache::get($key, true);

Deleting data

You may delete a single item from de cache using the delete() method:, (*13)

Cache::delete($key);

You may also flush all the cache to delete everything:, (*14)

Cache::flush();

Race conditions

This library makes atomic writes via rename, so no race condition should be possible., (*15)

Performance

There are some benchmarks over the benchmarks/ directory., (*16)

They're simple ones and you're encouraged to write more extensive ones. In general, the performance difference compared with memcached or apc is almost unnoticeable with large chunks of data, but it's relatively high with small data fragments. That's expected due to the fs access overhead., (*17)

There are also legacy tests by a contributor in the legacy-tests folder which test performance and race-condition ressistance., (*18)

The Versions

11/03 2017
04/01 2016

dev-test-refactor

dev-test-refactor https://github.com/ecoal95/php-cache

Minimal caching library

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

cache fs