{"id":13452944,"url":"https://github.com/happyfish100/libshmcache","last_synced_at":"2025-03-23T21:35:19.695Z","repository":{"id":14079399,"uuid":"75918346","full_name":"happyfish100/libshmcache","owner":"happyfish100","description":"libshmcache is a local cache in the share memory for multi processes. high performance due to read is lockless. libshmcache is 100+ times faster than a remote interface such as redis. ","archived":false,"fork":false,"pushed_at":"2024-01-23T16:46:40.000Z","size":536,"stargazers_count":445,"open_issues_count":24,"forks_count":133,"subscribers_count":37,"default_branch":"master","last_synced_at":"2024-08-01T08:06:56.348Z","etag":null,"topics":["cache","key-value","lockless","shared-memory"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/happyfish100.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-08T08:28:53.000Z","updated_at":"2024-08-01T02:46:43.000Z","dependencies_parsed_at":"2022-08-28T02:51:11.934Z","dependency_job_id":null,"html_url":"https://github.com/happyfish100/libshmcache","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happyfish100%2Flibshmcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happyfish100%2Flibshmcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happyfish100%2Flibshmcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happyfish100%2Flibshmcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/happyfish100","download_url":"https://codeload.github.com/happyfish100/libshmcache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221918549,"owners_count":16901644,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","key-value","lockless","shared-memory"],"created_at":"2024-07-31T08:00:28.871Z","updated_at":"2024-10-28T19:31:05.189Z","avatar_url":"https://github.com/happyfish100.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"Copyright (C) 2016 Happy Fish / YuQing\n\nlibshmcache may be copied or modified under the terms of BSD License.\n\nlibshmcache is a local share memory cache for multi processes.\nit is a high performance library because read mechanism is lockless.\nlibshmcache is 100+ times faster than a remote interface such as redis.\n\nthis project contains C library, PHP extension and Java JNI wrapper.\n\nIts high performance features include:\n  * pthread mutex lock on write, read is lockless\n  * use hash table for quickly setting, getting and deletion\n  * use object pool (FIFO queue) for hash/KV entry allocation\n  * use striping/block buffer allocator. in a memory striping,\n    allocate value buffer in order. just only decrease allocator's\n    used size when free the value buffer. recycle the whole memory\n    striping/allocator when it's used size reach to zero after memory free up.\n  * use FIFO elimination algorithm instead of LRU\n\nstable features are:\n  * deadlock detection and auto unlock that caused by other crushed process\n  * check some key fields for consistency when init, old share memories\n    should be cleaned and reinit when the memory related parameters changed\n  * add sleep time to avoid other processes reading dirty data when\n    recycle more than one valid (not expired) hash/KV entries\n\nother features are:\n  * support both related processes (such as parent process and subprocesses)\n    and unrelated processes (such as php-fpm and php CLI, two php CLI processes, etc.)\n  * incrementally allocate value buffer segment as need, this is controlled\n    by config parameter: segment_size\n  * provide abundant stats info: counters for set, get and delete,\n    memory recycle stats, lock stats etc.\n  * support atomic increment\n  * PHP extension support multiple serializers: igbinary, msgpack, php.\n    these serializers can coexist in a share memory.\n\nutility commands in directory: src/tools, in /usr/bin/ after make \u0026\u0026 make install\n  * shmcache_set: set a key\n  * shmcache_get: get a key\n  * shmcache_delete: delete a key\n  * shmcache_remove_all: remove the share memory\n  * shmcache_stats: show share memory statistics\n\n  * Note: the key size can not be longer than 64 bytes\n\nlibshmcache PHP extension is supplied in the directory: php-shmcache, support PHP 5 and PHP 7\n\nShmCache::__construct(string $config_filename[, long $serializer =\n        ShmCache::SERIALIZER_IGBINARY])\n  * @param config_filename: the config filename as conf/libshmcache.conf\n  * @param serializer: the serializer type\n    \u003cpre\u003e\n      ShmCache::SERIALIZER_IGBINARY for igbinary, the default serializer\n      ShmCache::SERIALIZER_MSGPACK for msgpack\n      ShmCache::SERIALIZER_PHP for php serializer\n    \u003c/pre\u003e\n  * @throws ShmCacheException if the serializer not enabled\n  * @example: $cache = new ShmCache(\"/etc/libshmcache.conf\");\n  * @note: igbinary and msgpack php extensions must be enabled before use them\n    \u003cpre\u003e\n    check method:\n    php -m | grep igbinary\n    php -m | grep msgpack\n    \u003c/pre\u003e\n\nboolean ShmCache::set(string $key, mixed $value, long $ttl)\n  * @param key: the key, must be a string variable\n  * @param value: the value, any php variable\n  * @param ttl: timeout / expire in seconds, such as 600 for ten minutes,\n    ShmCache::NEVER_EXPIRED for never expired\n  * @return true for success, false for fail\n  * @throws ShmCacheException if $value is false\n  * @example: $cache-\u003eset($key, $value, 300);\n\nlong ShmCache::incr(string $key, long $increment, long $ttl)\n  * @desc: atomic increment\n  * @param key: the key, must be a string variable\n  * @param increment: the increment integer, can be negative, such as -1\n  * @param ttl: timeout / expire in seconds, such as 600 for ten minutes,\n  * @return the value after increase, false for fail\n\nmixed ShmCache::get(string $key[, boolean $returnExpired = false])\n  * @param key: the key, must be a string variable\n  * @param returnExpired: if return expired key / value\n  * @return mixed value for success, false for key not exist or expired\n  * @example: $value = $cache-\u003eget($key);\n\nlong ShmCache::getExpires(string $key[, boolean $returnExpired = false])\n  * @desc: get expires time as unix timestamp\n  * @param key: the key, must be a string variable\n  * @param returnExpired: if return expired key / value\n  * @return expires timestamps such as 1483952635, 0 for never expired, false for not exist\n  * @example: $value = $cache-\u003egetExpires($key);\n\nboolean ShmCache::setExpires(string $key, long $expires)\n  * @param key: the key, must be a string variable\n  * @param expires: expires timestamp (unix timestamp eg. 1591347245)\n    ShmCache::NEVER_EXPIRED for never expired\n  * @return true for success, false for key not exist or expired or other error\n  * @throws ShmCacheException if $expires is invalid\n  * @example: $cache-\u003esetExpires($key, 1591347245);\n\nboolean ShmCache::setTTL(string $key, long $ttl)\n  * @param key: the key, must be a string variable\n  * @param ttl: timeout / expire in seconds, such as 600 for ten minutes,\n    ShmCache::NEVER_EXPIRED for never expired\n  * @return true for success, false for key not exist or expired or other error\n  * @throws ShmCacheException if $ttl is invalid\n  * @example: $cache-\u003esetTTL($key, 300);\n\nboolean ShmCache::delete(string $key)\n  * @param key: the key, must be a string variable\n  * @return true for success, false for fail\n  * @example: $cache-\u003edelete($key);\n\narray ShmCache::stats()\n  * @return stats array\n  * @example: echo json_encode($cache-\u003estats(), JSON_PRETTY_PRINT);\n\nboolean ShmCache::clear()\n  * @desc: clear hashtable to empty. use this function carefully because it will remove all keys in cache\n  * @return true for success, false for fail\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhappyfish100%2Flibshmcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhappyfish100%2Flibshmcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhappyfish100%2Flibshmcache/lists"}