{"id":18389547,"url":"https://github.com/netherphp/cache","last_synced_at":"2025-08-01T03:44:21.412Z","repository":{"id":16045679,"uuid":"18789631","full_name":"netherphp/cache","owner":"netherphp","description":"A cache interface.","archived":false,"fork":false,"pushed_at":"2021-06-08T20:27:55.000Z","size":89,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-18T08:16:42.303Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/netherphp.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}},"created_at":"2014-04-15T06:18:29.000Z","updated_at":"2021-06-08T20:25:16.000Z","dependencies_parsed_at":"2022-08-02T14:45:17.572Z","dependency_job_id":null,"html_url":"https://github.com/netherphp/cache","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/netherphp/cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netherphp%2Fcache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netherphp%2Fcache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netherphp%2Fcache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netherphp%2Fcache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/netherphp","download_url":"https://codeload.github.com/netherphp/cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netherphp%2Fcache/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268166280,"owners_count":24206428,"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","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-06T01:43:42.833Z","updated_at":"2025-08-01T03:44:21.368Z","avatar_url":"https://github.com/netherphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nether Cache\n\nLightweight management of cache storage and retrieval.\n\n* `LocalEngine` - caches data in local memory while the app is running.\n* `MemcacheEngine` - accesses memcached network cache.\n* `FilesystemEngine` - cache data as files.\n\nAdditional cache engines can be implemented with `EngineInterface`.\n\nLicenced under BSD-2-Clause-Patent. See LICENSE for details.\n\n# Usage\n\n## Low Level\n\nCreate a cache manager and throw cache engines into it. If no priority value is\nset then the priorities will be set such that the caches will always be checked\nFIFO. In this example case the LocalEngine will always be checked before the\nMemcacheEngine which will aways be checked before the FilesystemEngine. The\npriorties can be used to stack caches from fastest to slowest.\n\n```php\n$Manager = new Nether\\Cache\\Manager;\n\n$Manager\n-\u003eEngineAdd(new Nether\\Cache\\Engines\\LocalEngine)\n-\u003eEngineAdd(new Nether\\Cache\\Engines\\MemcacheEngine(\n\tServers: [ 'localhost:11211' ]\n))\n-\u003eEngineAdd(new Nether\\Cache\\Engines\\FilesystemEngine(\n\tPath: '/where/ever'\n));\n```\n\nThrow data into the caches, ask about it, and get it back out.\n\n```php\n$Manager-\u003eSet('unique-id','value');\n\nvar_dump(\n\t$Manager-\u003eHas('unique-id'),\n\t$Manager-\u003eGet('unique-id')\n);\n\n// bool(true)\n// string(5) \"value\"\n```\n\nDelete data from the caches.\n\n```php\n$Manager-\u003eDrop('unique-id');\n\nvar_dump(\n\t$Manager-\u003eHas('unique-id'),\n\t$Manager-\u003eGet('unique-id')\n);\n\n// bool(false)\n// NULL\n```\n\n## Debugging\n\nThe contents of the cache are wrapped with a small descriptor object that describes the data, and can be inspected by getting a cache object rather than the cache data directly.\n\n* `CacheObject-\u003eTime` is the unix timestamp the data was added to the cache.\n* `CacheObject-\u003eEngine` will be the the cache engine instance that the data was found in.\n* `CacheObject-\u003eOrigin` will be NULL unless it is defined when data is set. It is meant to be meta to trace what part of a project pushed the data into the cache.\n\n```php\n$Manager-\u003eSet('test', 'geordi', Origin:'engineering');\nprint_r($Manager-\u003eGetCacheObject('unique-id'));\n```\n\n```\nNether\\Cache\\Struct\\CacheObject Object\n(\n\t[Data]   =\u003e geordi\n\t[Time]   =\u003e 1622487745\n\t[Origin] =\u003e engineering\n\t[Engine] =\u003e Nether\\Cache\\Engines\\LocalEngine Object\n\t\t(\n\t\t\t[...]\n\t\t)\n)\n```\n\n# LocalEngine\n\n```php\nnew Nether\\Cache\\Engines\\LocalEngine(\n\tUseGlobal: bool\n);\n```\n\nSetting UseGlobal to TRUE will allow multiple instances to access the same\ndataset. This would allow creation of instances when needed rather than early\nin an app and stored as a singleton somewhere.\n\nThe way this engine works is literally it is just an array that is local\nto this currently running application. Why ask Memcached for the same thing\ntwice if we could remember it the first time?\n\n# MemcacheEngine\n\n```php\nnew Nether\\Cache\\Engines\\MemcacheEngine(\n\tUseGlobal: bool,\n\tMemcache: Memcache|null\n);\n```\n\nSetting UseGlobal to TRUE will allow multiple instances to access the same\ndefined server pool. This would allow creation of instances when needed rather\nthan early in an app and stored as a singleton somewhere.\n\nProviding a Memcache instance will use whatever pool that instance was built\nwith. Additionally, this allows dependency injection of a mock for testing.\n\n`Engine-\u003eServerAdd(string Host, int Port=11211)`\n\nAdd servers to the Memcache pool.\n\n# FilesystemEngine\n\n```php\nnew Nether\\Cache\\Engines\\FilesystemEngine(\n\tPath: string,\n\tUseHashType: string|NULL,\n\tUseHashStruct: bool\n\tUseFullDrop: bool\n);\n```\n\nPath is the only required argument, that being the path to the directory where\ncache data should be stored.\n\nBy default the filesystem engine works just like the others. Store data under\nthe key \"test\" and get a file called \"test\" in the directory the engine is\npointing at. There are additional features though to help make the filesystem\nengine more robust at larger scales.\n\n`Engine-\u003eUseHashType(?string HashAlgoName)`\n\nGiven any hash name supported by your system instead of storing the cache file\nas a literal file called \"test\" it will be called whatever it hashes out to be.\nSetting it to NULL will disable the hashing.\n\n`Engine-\u003eUseHashStruct(bool Should)`\n\nIf TRUE the engine will mess around with the final filename a bit to help avoid\nhitting filesystem limits for maximum files in a directory. Given a filename\nhash worked out to `abcdef` it will be transformed to be `ab/cdef` to help\ndistribute the cache files across many directories. As of the time of this\nwriting, this is the same as how Git stores its object files in the .git\nfolders.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetherphp%2Fcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetherphp%2Fcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetherphp%2Fcache/lists"}