Download the PHP package romeoz/rock-cache without Composer
On this page you can find all versions of the php package romeoz/rock-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download romeoz/rock-cache
More information about romeoz/rock-cache
Files in romeoz/rock-cache
Package rock-cache
Short Description Unified API for key-value storages in memory. As a storage can be used: APC, Redis, Memcache, Couchbase or MongoDB. All storage objects have one interface, so you can switch them without changing the working code.
License MIT
Informations about the package rock-cache
Cache library
What storages can be used:
All storage objects have one interface, so you can switch them without changing the working code.
Features
- One interface for all storages - you can change storage without changing your code
- Tagging cache (approach versioning and grouping)
- Locking - "race condition" ("dog-pile" or "cache miss storm") effects are excluded
- Serializer for value (json or PHP-serializer)
- Automatic unserialization
- Standalone module/component for Rock Framework
Table of Contents
- Installation
- Quick Start
- Memcached
- MongoDB
- Locking key
- Documentation
- Demo
- Requirements
- Storages comparison
- Differences between the approaches a tagging
- Grouping tags
- Versioning tags
Installation
From the Command Line:
or in your composer.json:
Quick Start
Memcached
MongoDB
Locking key
Race conditions can occur in multi-threaded mode. To avoid the effect, you need to install a lock on the key.
Documentation
get($key)
Returns value by key.
getMulti(array $keys)
Returns multiple values by keys.
set($key, mixed $value, $expire = 0, array $tags = null)
Sets a value to cache.
setMulti($key, mixed $value, $expire = 0, array $tags = null)
Sets a multiple key-values to cache.
add($key, mixed $value, $expire = 0, array $tags = null)
Adds a value to cache.
Return false, if already exists on the server.
exists($key)
Checks existence key.
touch($key, $expire = 0)
Changes expire (TTL) for key.
touchMulti(array $keys, $expire = 0)
Changes expire (TTL) for multiple keys .
increment($key, $offset = 1, $expire = 0, $create = true)
Increment a value to cache.
decrement($key, $offset = 1, $expire = 0, $create = true)
Decrement a value to cache.
remove($key)
Removes value from cache.
removeMulti(array $keys)
Removes multiple values from cache.
getTag($tag)
Returns a keys in accordance with tag.
getMultiTags(array $tags)
Returns a keys in accordance with multiple tags.
existsTag($tag)
Checks existence tag.
removeTag($tag)
Removes a tag.
removeMultiTag(array $tags)
Removes a multiple tags.
getAllKeys()
Returns all keys.
Supported:
Memcached
,Redis
,APC
.
getAll()
Returns all values.
Supported:
Memcached
,APC
.
lock($key)
Sets a lock on the key.
unlock($key)
Unlocking key.
flush()
Removes all values from cache.
status()
Returns a status server.
Supported:
Memcached
,Memcache
,Redis
,APC
,Couchbase
.
getStorage()
Returns a native instance cache-storage.
Demo
- Install Docker or askubuntu
docker run --name demo -d -p 8080:80 romeoz/docker-rock-cache
- Open demo http://localhost:8080/
Requirements
You can use each storage separately, requirements are individually for storages.
- PHP 5.4+ and 7.0+
- Redis 2.8/3.0/3.2/4.0. Should be installed
apt-get install redis-server
ordocker run --name redis -d -p 6379:6379 romeoz/docker-redis:4.0
(recommended). Also should be installed PHP extensionapt-get install php-redis
- Memcached. Should be installed
apt-get install memcached
ordocker run --name memcached -d -p 11211:11211 romeoz/docker-memcached
(recommended). Also should be installed php-extension Memcacheapt-get install php-memcache
or Memcachedapt-get install php-memcached
.php-extension Memcached require dependencies
- APCu. Should be installed
apt-get install php-apcu
.For PHP 5.6 and lower allowed pecl-extensions APCu 4.0 and lower. Example installation.
- Couchbase DB 4.x.x. PHP 5.6 or higher, php-extension couchbase 2.3.x-2.4.x. Step-by-step installation or
docker run --name couchbase -d couchbase/server:community-4.1.1
(Example installation). - MongoDB 2.6-3.0. For using MongoDB as storage required Rock MongoDB:
composer require romeoz/rock-mongodb
All unbolded dependencies is optional
There is a ready docker-container: docker run --name phpfpm_full -d romeoz/docker-phpfpm:5.6-full
.
But, it may be redundant for you because of the many of installed pecl-extensions
Storages comparison
Redis is the best key-value storage for cache. Use Couchbase if you need fault-tolerant and very easy scalable cluster and if you can afford it (recommended hardware requirements). Also, data in Redis and Couchbase storages will be restored even after server reboot.
Differences between the approaches a tagging
Grouping tags
Fastest method, but there is a possibility of overflow cache.
Set a value:
View in memory:
Removing tag:
View in memory:
Versioning tags
Is the best practice, but slower than the approach with the grouping tags, because when getting the cache containing tags, sent multiple requests to compare versions. There is no cache overflows.
References: nablas by D.Koterov (RUS) or "Reset group caches and tagging" by A.Smirnov (RUS).
Set a value:
View in memory:
Removing tag:
View in memory:
Returns value:
View in memory:
License
The Rock Cache library is open-sourced software licensed under the MIT license