All Projects → ihor → Cachalot

ihor / Cachalot

Licence: MIT license
Caching rethought – cache a lot in a proper way.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to Cachalot

lua-resty-couchbase
Lua couchbase client driver for the ngx_lua based on the cosocket API / 使用cosocket纯lua实现的couchbase的client,已经在爱奇艺重要的服务播放服务稳定运行5年多
Stars: ✭ 77 (+208%)
Mutual labels:  couchbase
Phpfastcache
A high-performance backend cache system. It is intended for use in speeding up dynamic web applications by alleviating database load. Well implemented, it can drops the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful.
Stars: ✭ 2,171 (+8584%)
Mutual labels:  couchbase
easy-extends
一个简单快速安装PHP扩展的程序--最简单的方法就是使用Linux
Stars: ✭ 78 (+212%)
Mutual labels:  memcache
couchbase-index-manager
Command-line interface to manage Couchbase indexes, synchronizing them to index definitions.
Stars: ✭ 14 (-44%)
Mutual labels:  couchbase
doc2graph
Convert JSON from document-oriented DB to neo4j graph
Stars: ✭ 17 (-32%)
Mutual labels:  couchbase
rust-memcache
memcache client for rust
Stars: ✭ 106 (+324%)
Mutual labels:  memcache
synctos
The Syncmaker. A tool to build comprehensive sync functions for Couchbase Sync Gateway.
Stars: ✭ 51 (+104%)
Mutual labels:  couchbase
memcache.php
An APC-like stats/info page for your memcached servers.(unix socket support)
Stars: ✭ 20 (-20%)
Mutual labels:  memcache
showfast
Performance dashboard
Stars: ✭ 18 (-28%)
Mutual labels:  couchbase
memcache.php
Visibility for your memcache servers.
Stars: ✭ 54 (+116%)
Mutual labels:  memcache
CouchDraw
A synchronized drawing app that utilizes Couchbase Sync Gateway and Xamarin to enable shared canvases.
Stars: ✭ 22 (-12%)
Mutual labels:  couchbase
neo4j-couchbase-connector
Neo4j - Couchbase Connection API
Stars: ✭ 14 (-44%)
Mutual labels:  couchbase
sidecache
Sidecar cache for kubernetes applications.
Stars: ✭ 38 (+52%)
Mutual labels:  couchbase
Jdempotent
Make your consumer, API, etc. idempotent easily.
Stars: ✭ 62 (+148%)
Mutual labels:  couchbase
couchmove
Java data migration tool for Couchbase
Stars: ✭ 36 (+44%)
Mutual labels:  couchbase
couchbase-exporter
Prometheus Couchbase 5 Exporter, Grafana dashboard and Alerting rules included
Stars: ✭ 41 (+64%)
Mutual labels:  couchbase
couchbase-java-importer
This is a pluggable importer for Couchbase
Stars: ✭ 13 (-48%)
Mutual labels:  couchbase
couchbase exporter
Export metrics from Couchbase Server for Prometheus consumption
Stars: ✭ 32 (+28%)
Mutual labels:  couchbase
docker-php7
A docker image with php 7 and extensions (apc, apcu, intl, mcrypt,...)
Stars: ✭ 16 (-36%)
Mutual labels:  apcu
docker-couchbase-server
🎪 Couchbase Server clusters on Docker
Stars: ✭ 20 (-20%)
Mutual labels:  couchbase

Cachalot

Cachalot (cache a lot) is an easy to use caching library. It supposed to do the only one thing - return cached callback result.

Installation

Define the following requirement in your composer.json file:

"require": {
    "ihor/cachalot": "2.3"
}

Usage

// With Cachalot cache you can easily cache results of different types of functions
$cache = new \Cachalot\ArrayCache();

// built-in functions
$length = $cache->getCached('strlen', ['hello world']); 

// user defined functions
$unique = $cache->getCached('uniqueValues', [[1, 2, 3, 1, 2, 3]]);

// static methods
$result = $cache->getCached(['Calculator', 'subtract'], [1, 2]);

// instance methods
$square = $cache->getCached([new Calculator(), 'square'], [5]);

// anonymous functions
$reason = $cache->getCached($getErrorReason, [], \Cachalot\Cache::ONE_DAY, 'error-reason');

// callable objects
$trimed = $cache->getCached(new Trimmer(), [' hello world ']);

Reference

Cache API

getCached($callback, array $args = array(), $expireIn = 0, $suffix = null, $useSuffixAsKey = false)

Returns cached $callback result

$callback is the function (callable) which results we want to be cached
$args are the arguments passed to the $callback
$expireIn sets cache TTL in seconds
$suffix is needed to avoid collisions when callback is an anonymous function $useSuffixAsKey when true cache suffix will be used as a cache key

$length = $cache->getCached('strlen', ['hello world']);

To have possibility to use Cachalot as a regular caching library when needed it contains classic cache methods

contains($key)

Returns true if cache contains entry with given key

if ($cache->contains('lastVisit')) {
    echo 'This is not the first visit';
}
get($key)

Returns cached value by key or false if there is no cache entry for the given key

if ($lastVisitDate = $cache->get('lastVisit')) {
    echo sprintf('Last visit was at %s', $lastVisitDate);
}
set($key, $value, $expireIn = 0)

Caches value by key. When $expireIn = 0 the value is cached forever

$cache->set('lastVisit', time());
delete($key)

Deletes cache entry by key

$cache->delete('lastVisit');
clear()

Deletes all cache entries

$cache->clear();

Back-ends

Cachalot\ApcCache

Stores data in APC

$cache = new Cachalot\ApcCache();
Cachalot\XcacheCache

Stores data in Xcache

$cache = new Cachalot\XcacheCache();
Cachalot\MemcacheCache

Stores data in Memcached using Memcache PHP extension

$memcache = new \Memcache();
$memcache->connect('unix:///usr/local/var/run/memcached.sock', 0);

$cache = new \Cachalot\MemcacheCache($memcache);
Cachalot\MemcachedCache

Stores data in Memcached using Memcached PHP extension

$memcached = new \Memcached();
$memcached->addServer('/usr/local/var/run/memcached.sock', 0);

$cache = new \Cachalot\MemcachedCache($memcached);
Cachalot\RedisCache

Stores data in Redis

$redis = new \Redis();
$redis->connect('127.0.0.1');
$redis->select(1);

$cache = new \Cachalot\RedisCache($redis);
Cachalot\CouchbaseCache

Stores data in Couchbase using Couchbase PHP SDK 1.x

$couchbase = new \Couchbase('127.0.0.1', '', '', 'default');

$cache = new \Cachalot\CouchbaseCache($couchbase);
Cachalot\Couchbase2Cache

Stores data in Couchbase using Couchbase PHP SDK 2.x

$cluster = new \CouchbaseCluster('couchbase://localhost');
$bucket = $cluster->openBucket('default');

$cache = new \Cachalot\Couchbase2Cache($bucket);
Cachalot\ArrayCache

Stores data in PHP array

$cache = new \Cachalot\ArrayCache();
Cachalot\BlackholeCache

Never stores any data

$cache = new \Cachalot\BlackholeCache();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].