libshmcache may be copied or modified under the terms of BSD License.
libshmcache is a local share memory cache for multi processes.
it is a high performance library because read mechanism is lockless.
libshmcache is 100+ times faster than a remote interface such as redis.
this project contains C library, PHP extension and Java JNI wrapper.
Its high performance features include:
pthread mutex lock on write, read is lockless
use hash table for quickly setting, getting and deletion
use object pool (FIFO queue) for hash/KV entry allocation
use striping/block buffer allocator. in a memory striping,
allocate value buffer in order. just only decrease allocator’s
used size when free the value buffer. recycle the whole memory
striping/allocator when it’s used size reach to zero after memory free up.
use FIFO elimination algorithm instead of LRU
stable features are:
deadlock detection and auto unlock that caused by other crushed process
check some key fields for consistency when init, old share memories
should be cleaned and reinit when the memory related parameters changed
add sleep time to avoid other processes reading dirty data when
recycle more than one valid (not expired) hash/KV entries
other features are:
support both related processes (such as parent process and subprocesses)
and unrelated processes (such as php-fpm and php CLI, two php CLI processes, etc.)
incrementally allocate value buffer segment as need, this is controlled
by config parameter: segment_size
provide abundant stats info: counters for set, get and delete,
memory recycle stats, lock stats etc.
support atomic increment
PHP extension support multiple serializers: igbinary, msgpack, php.
these serializers can coexist in a share memory.
utility commands in directory: src/tools, in /usr/bin/ after make && make install
shmcache_set: set a key
shmcache_get: get a key
shmcache_delete: delete a key
shmcache_remove_all: remove the share memory
shmcache_stats: show share memory statistics
Note: the key size can not be longer than 64 bytes
libshmcache PHP extension is supplied in the directory: php-shmcache, support PHP 5 and PHP 7
ShmCache::__construct(string $config_filename[, long $serializer =
ShmCache::SERIALIZER_IGBINARY])
@param config_filename: the config filename as conf/libshmcache.conf
@param serializer: the serializer type
ShmCache::SERIALIZER_IGBINARY for igbinary, the default serializer
ShmCache::SERIALIZER_MSGPACK for msgpack
ShmCache::SERIALIZER_PHP for php serializer
@throws ShmCacheException if the serializer not enabled
@example: $cache = new ShmCache(“/etc/libshmcache.conf”);
@note: igbinary and msgpack php extensions must be enabled before use them
Copyright (C) 2016 Happy Fish / YuQing
libshmcache may be copied or modified under the terms of BSD License.
libshmcache is a local share memory cache for multi processes. it is a high performance library because read mechanism is lockless. libshmcache is 100+ times faster than a remote interface such as redis.
this project contains C library, PHP extension and Java JNI wrapper.
Its high performance features include:
stable features are:
other features are:
utility commands in directory: src/tools, in /usr/bin/ after make && make install
shmcache_set: set a key
shmcache_get: get a key
shmcache_delete: delete a key
shmcache_remove_all: remove the share memory
shmcache_stats: show share memory statistics
Note: the key size can not be longer than 64 bytes
libshmcache PHP extension is supplied in the directory: php-shmcache, support PHP 5 and PHP 7
ShmCache::__construct(string $config_filename[, long $serializer = ShmCache::SERIALIZER_IGBINARY])
boolean ShmCache::set(string $key, mixed $value, long $ttl)
long ShmCache::incr(string $key, long $increment, long $ttl)
mixed ShmCache::get(string $key[, boolean $returnExpired = false])
long ShmCache::getExpires(string $key[, boolean $returnExpired = false])
boolean ShmCache::setExpires(string $key, long $expires)
boolean ShmCache::setTTL(string $key, long $ttl)
boolean ShmCache::delete(string $key)
array ShmCache::stats()
boolean ShmCache::clear()