{"id":22477547,"url":"https://github.com/maplephp/cache","last_synced_at":"2026-02-05T23:01:06.984Z","repository":{"id":209521777,"uuid":"644769408","full_name":"MaplePHP/Cache","owner":"MaplePHP","description":"MaplePHP Cache is a simple, user-friendly caching library. It offers seamless compatibility with PSR-6 and PSR-16 for PHP applications.","archived":false,"fork":false,"pushed_at":"2025-10-26T11:20:17.000Z","size":66,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-26T13:15:12.884Z","etag":null,"topics":["cache","cache-engine","filesystem","memcache","memcached","php","psr-16","psr-6","psr-6-psr-16","simple-cache","storage"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MaplePHP.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":"2023-05-24T08:10:30.000Z","updated_at":"2024-05-31T22:21:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"7704df58-aa5d-4587-8a33-7176d46958e7","html_url":"https://github.com/MaplePHP/Cache","commit_stats":null,"previous_names":["maplephp/cache"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/MaplePHP/Cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaplePHP%2FCache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaplePHP%2FCache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaplePHP%2FCache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaplePHP%2FCache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MaplePHP","download_url":"https://codeload.github.com/MaplePHP/Cache/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaplePHP%2FCache/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29137750,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T22:49:08.052Z","status":"ssl_error","status_checked_at":"2026-02-05T22:45:32.059Z","response_time":65,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["cache","cache-engine","filesystem","memcache","memcached","php","psr-16","psr-6","psr-6-psr-16","simple-cache","storage"],"created_at":"2024-12-06T14:11:30.713Z","updated_at":"2026-02-05T23:01:06.978Z","avatar_url":"https://github.com/MaplePHP.png","language":"PHP","readme":"\n# MaplePHP - Cache\nMaplePHP Cache, a clean and user-friendly caching library. MaplePHP Cache is designed to provide a seamless caching experience with simplicity and ease of use as its core principles. Whether you're familiar with **PSR-6** or **PSR-16**, this library offers a smooth and intuitive caching solution for your PHP applications.\n\n## Installation\n```\ncomposer require maplephp/cache\n```\n\n## Initiate the cache engine\nStart with initiate  the MaplePHP Cache class and pass on a Handler to it. \n```php\nuse MaplePHP\\Cache\\Cache;\nuse MaplePHP\\Cache\\Handlers\\FileSystemHandler;\n\n$cache = new Cache(new FileSystemHandler(dirname(__FILE__).\"/storage/cache\"));\n```\n\n## Usage\nIt is super easy to use\n```php\n$expireInOneHour = 3600; // 3600 seconds = 1 hour\nif(!$cache-\u003ehas(\"test\") \u0026\u0026 $cache-\u003eset(\"test\", \"Lorem ipsum dolor\", $expireInOneHour)) {\n\techo \"Cache has been set\u003cbr\u003e\";\n}\necho \"Get cache: \".$cache-\u003eget(\"test\");\n```\n### Error handling\nWhile not required, it is advisable to handle critical throwable errors that may occur, such as an invalid cache key, insufficient file permissions, or possible connection issues with a cache server. Logging these exceptions can be beneficial for error tracking and troubleshooting purposes. \n```php\n$cache = new Cache(new FileSystemHandler(dirname(__FILE__)));\ntry {\n\t// Invalid key set\n\tprint_r($cache-\u003eget(\"te st\"));\n} catch (Exception $e) {\n\t// Will trigger: Invalid cache key. Only alphanumeric characters, underscores, and dots are allowed.\n\techo $e-\u003egetMessage();\n}\n```\n\n## Handlers\n\n### File system\nSave cache as a file on you system.\n\n**Arg1:** (string) Path to directory where you want to save the cache fiels\n```php\nuse MaplePHP\\Cache\\Handlers\\FileSystemHandler;\n$fileSystem = new FileSystemHandler(dirname(__FILE__).\"/storage/cache\");\n```\n\n### Memcached\nUse Memcached to save cache in memory **(high performance)**\n\n**Arg1:** (string|array) Host to server (or get default with class constant \"MemcachedHandler::HOST\")\n\n**Arg2:** (int|null) Port to server (or get default with class constant \"MemcachedHandler::PORT\")\n\n**Arg3:** (int) Weight to server (Arg is default 0 but you can also set it with default with class constant \"MemcachedHandler::WEIGHT\")\n```php\nuse MaplePHP\\Cache\\Handlers\\MemcachedHandler;\n// One server\n$memcached = new MemcachedHandler(MemcachedHandler::HOST, MemcachedHandler::PORT, MemcachedHandler::WEIGHT);\n// Multiple servers\n$memcached = new MemcachedHandler([\n\t[\"Memcached.server1.com\", 11211, 1], // Weight \"1\" (this server has priority)\n\t[\"Memcached.server2.com\", 11212, 2],\n\t[\"Memcached.server3.com\", 11300, 3]\n]);\n```\n\n## Command list (PSR-16)\n#### Get a cache item\nCan return mixed values if successful if miss then return default value. The default value is **not** required and is by default **null**.\n```php\n$cache-\u003eget(\"test\", \"Default value\");\n```\n#### Check if cache item exists\nWill return bool\n```php\n$cache-\u003ehas(\"test\");\n```\n#### Set a cache item\nIt is allowed to set cache values of mixed types like strings, arrays and including PSR-7: HTTP Streams. Will return bool.\n```php\n// Set cache with 1 hour lifetime\n$cache-\u003eset(\"test\", \"Lorem ipsum dolor\", 3600);\n// Set cache that will persist\n$cache-\u003eset(\"test2\", \"Lorem ipsum dolor\");\n```\n#### Delete a cache item\nWill return bool\n```php\n$cache-\u003edelete(\"test\");\n```\n#### Clear and auto delete all cache items\nWill return bool\n```php\n$cache-\u003eclear();\n```\n#### Get multiple cache items\nWill return array with mixed values if successful, if miss then return default value. The default value is **not** required and is by default **null**.\n```php\n$cache-\u003egetMultiple([\"test1\", \"test2\"], \"Default value\");\n```\n#### Set multiple cache items\nWill return bool \n```php\n$cache-\u003esetMultiple([\"test1\" =\u003e \"Lorem\", \"test2\" =\u003e \"Ipsum\"], 3600);\n```\n#### Delete multiple cache items\nWill return bool\n```php\n$cache-\u003edeleteMultiple([\"test1\", \"test2\"]);\n```\n## PSR-6 Example\nIf your application needs advanced caching features, hierarchical caching, or cache tagging, PSR-6 is a more suitable choice.\n```php\n\nuse MaplePHP\\Cache\\Handlers\\FileSystemHandler;\n$cache = new FileSystemHandler(dirname(__FILE__).\"/storage/cache\");\n\n$item = $cache-\u003egetItem('test');\n\ntry {\n\tif(!$item-\u003eisHit()) {\n\t\t$item-\u003eset([\"Lorem 1\", \"Lorem 2\"])-\u003eexpiresAfter(3600);\n\t\t$cache-\u003esave($item);\n\n\t\techo \"Insert to cache: \";\n\t\tprint_r($item-\u003eget());\n\n\t} else {\n\t\techo \"Read from cache: \";\n\t\tprint_r($item-\u003eget());\n\t}\n\n} catch (Exception $e) {\n\techo $e-\u003egetMessage();\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaplephp%2Fcache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaplephp%2Fcache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaplephp%2Fcache/lists"}