{"id":13469811,"url":"https://github.com/laruence/yac","last_synced_at":"2025-05-16T07:03:52.916Z","repository":{"id":7451904,"uuid":"8795150","full_name":"laruence/yac","owner":"laruence","description":"A fast, lock-free, shared memory user data cache for PHP","archived":false,"fork":false,"pushed_at":"2024-06-28T10:50:52.000Z","size":279,"stargazers_count":829,"open_issues_count":19,"forks_count":198,"subscribers_count":74,"default_branch":"master","last_synced_at":"2025-04-08T16:07:36.183Z","etag":null,"topics":["c","cache","cache-storage","lock-free","php","shared-memory","yac"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/laruence.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-03-15T08:48:14.000Z","updated_at":"2025-03-27T19:28:27.000Z","dependencies_parsed_at":"2024-06-28T10:30:33.170Z","dependency_job_id":"933e37cf-adec-4be8-8f7d-225d97b48a54","html_url":"https://github.com/laruence/yac","commit_stats":{"total_commits":277,"total_committers":24,"mean_commits":"11.541666666666666","dds":"0.29241877256317694","last_synced_commit":"df64efc0ab34fa705a7019d38031cfa11c825e1b"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laruence%2Fyac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laruence%2Fyac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laruence%2Fyac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laruence%2Fyac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/laruence","download_url":"https://codeload.github.com/laruence/yac/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254485053,"owners_count":22078767,"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":["c","cache","cache-storage","lock-free","php","shared-memory","yac"],"created_at":"2024-07-31T16:00:16.870Z","updated_at":"2025-05-16T07:03:52.887Z","avatar_url":"https://github.com/laruence.png","language":"C","readme":"# Yac - Yet Another Cache\n[![Build status](https://ci.appveyor.com/api/projects/status/6bu09pw8ukyx61m2/branch/master?svg=true)](https://ci.appveyor.com/project/laruence/yac/branch/master) [![Build Status](https://github.com/laruence/yac/workflows/integrate/badge.svg)](https://github.com/laruence/yac/actions?query=workflow%3Aintegrate)\n\nYac is a shared and lockless memory user data cache for PHP.\n\nit can be used to replace APC or local memcached.\n\n## Requirement\n\n- PHP 7 +\n\n### Install\n\n```\n$/path/to/phpize\n$./configure --with-php-config=/path/to/php-config\n$make \u0026\u0026 make install\n```\n\n## Note\n\n1.  Yac is a lockless cache, you should try to avoid or reduce the probability of multiple processes set one same key\n2.  Yac use partial crc, you'd better re-arrange your cache content, place the most important(mutable) bytes at the head or tail\n\n## Restrictions\n\n1.  Cache key cannot be longer than 48 (YAC_MAX_KEY_LEN) bytes\n2.  Cache Value cannot be longer than 64M (YAC_MAX_VALUE_RAW_LEN) bytes\n3.  Cache Value after compressed cannot be longer than 1M (YAC_MAX_VALUE_COMPRESSED_LEN) bytes\n\n## InIs\n````\nyac.enable = 1\n\nyac.keys_memory_size = 4M ; 4M can get 30K key slots, 32M can get 100K key slots\n\nyac.values_memory_size = 64M\n\nyac.compress_threshold = -1\n\nyac.enable_cli = 0 ; whether enable yac with cli, default 0\n\nyac.serializer = php ; since yac 2.2.0 , specific seralizer yac used\n                       could be json(--enable-json), msgpack(--enable-msgpack) or igbinary(--enable-igbinary)\n````\n## Constants\n````\nYAC_VERSION\n\nYAC_MAX_KEY_LEN = 48 ; if your key is longer than this, maybe you can use md5 result as the key\n\nYAC_MAX_VALUE_RAW_LEN = 64M\n\nYAC_MAX_VALUE_COMPRESSED_LEN = 1M\n\nYAC_SERIALIZER_PHP = 0   ; since yac-2.2.0\n\nYAC_SERIALIZER_JSON = 1  ; since yac-2.2.0\n\nYAC_SERIALIZER_MSGPACK = 2 ; since yac-2.2.0\n\nYAC_SERIALIZER_IGBINARY = 3 ; since yac-2.2.0\n\nYAC_SERIALIZER  ; serializer according to yac.serializer, default is YAC_SERIALIZER_PHP\n````\n## Methods\n\n### Yac::\\_\\_construct\n\n```php\n   Yac::__construct([string $prefix = \"\"])\n```\n\nConstructor of Yac, you can specify a prefix which will used to prepend to any keys when doing set/get/delete\n\n```php\n\u003c?php\n   $yac = new Yac(\"myproduct_\");\n?\u003e\n```\n\n### Yac::set\n\n```php\n   Yac::set($key, $value[, $ttl = 0])\n   Yac::set(array $kvs[, $ttl = 0])\n```\n\nStore a value into Yac cache, keys are cache-unique, so storing a second value with the same key will overwrite the original value.\n\nReturn true on success, return false on error (Like no memory, can not obtain cas write right)\n```php\n\u003c?php\n$yac = new Yac();\n$yac-\u003eset(\"foo\", \"bar\");\n$yac-\u003eset(\n    array(\n        \"dummy\" =\u003e \"foo\",\n        \"dummy2\" =\u003e \"foo\",\n        )\n    );\n?\u003e\n```\n#### Note:\nAs Yac 2.1, Store may failure if cas competition fails, you may need to do:\n```php\nwhile (!($yac-\u003eset(\"important\", \"value\")));\n```\nif you need the value to be stored properly.\n\n### Yac::get\n\n```\n   Yac::get(array|string $key[, \u0026$cas = NULL])\n```\n\nFetches a stored variable from the cache. If an array is passed then each element is fetched and returned.\n\nReturn the value on success, return false on error(Like no memory, can not obtain cas write right)\n```php\n\u003c?php\n$yac = new Yac();\n$yac-\u003eset(\"foo\", \"bar\");\n$yac-\u003eset(\n    array(\n        \"dummy\" =\u003e \"foo\",\n        \"dummy2\" =\u003e \"foo\",\n        )\n    );\n$yac-\u003eget(\"dummy\");\n$yac-\u003eget(array(\"dummy\", \"dummy2\"));\n?\u003e\n```\n\n### Yac::delete\n\n```\n   Yac::delete(array|string $keys[, $delay=0])\n```\n\nRemoves a stored variable from the cache. If delay is specified, then the value will be deleted after \\$delay seconds.\n\n### Yac::flush\n\n```\n   Yac::flush()\n```\n\nImmediately invalidates all existing items. it doesn't actually free any resources, it only marks all the items as invalid.\n\n### Yac::info\n\n```\n   Yac::info(void)\n```\n\nGet cache info\n\n```php\n\u003c?php\n  ....\n  var_dump($yac-\u003einfo());\n  /* will return an array like:\n  array(11) {\n      [\"memory_size\"]=\u003e int(541065216)\n      [\"slots_memory_size\"]=\u003e int(4194304)\n      [\"values_memory_size\"]=\u003e int(536870912)\n      [\"segment_size\"]=\u003e int(4194304)\n      [\"segment_num\"]=\u003e int(128)\n      [\"miss\"]=\u003e int(0)\n      [\"hits\"]=\u003e int(955)\n      [\"fails\"]=\u003e int(0)\n      [\"kicks\"]=\u003e int(0)\n      [\"slots_size\"]=\u003e int(32768)\n      [\"slots_used\"]=\u003e int(955)\n  }\n  */\n```\n","funding_links":[],"categories":["C","缓存( Caching )"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaruence%2Fyac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaruence%2Fyac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaruence%2Fyac/lists"}