{"id":15651583,"url":"https://github.com/voku/simple-cache","last_synced_at":"2025-04-10T02:23:13.530Z","repository":{"id":26406137,"uuid":"29856102","full_name":"voku/simple-cache","owner":"voku","description":":zap: Simple Cache Abstraction Layer for PHP","archived":false,"fork":false,"pushed_at":"2024-07-27T00:41:55.000Z","size":264,"stargazers_count":32,"open_issues_count":9,"forks_count":11,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-10-29T22:53:23.520Z","etag":null,"topics":["cache","cache-storage","caching-library","caching-strategies","hacktoberfest","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/voku.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","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},"funding":{"github":["voku"],"patreon":"voku","tidelift":"packagist/voku/simple-cache","custom":"https://www.paypal.me/moelleken"}},"created_at":"2015-01-26T10:25:54.000Z","updated_at":"2024-01-28T17:26:17.000Z","dependencies_parsed_at":"2024-03-04T13:04:56.066Z","dependency_job_id":"9c5ccfa6-7041-4ffd-bde4-fd94c0cf421f","html_url":"https://github.com/voku/simple-cache","commit_stats":{"total_commits":171,"total_committers":11,"mean_commits":"15.545454545454545","dds":0.6842105263157895,"last_synced_commit":"d6578b2b1c7a1ed36c4a862cae826b703520e73b"},"previous_names":[],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voku%2Fsimple-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voku%2Fsimple-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voku%2Fsimple-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voku%2Fsimple-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/voku","download_url":"https://codeload.github.com/voku/simple-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246905844,"owners_count":20852818,"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","cache-storage","caching-library","caching-strategies","hacktoberfest","php"],"created_at":"2024-10-03T12:39:12.615Z","updated_at":"2025-04-02T23:13:06.949Z","avatar_url":"https://github.com/voku.png","language":"PHP","readme":"[![Build Status](https://travis-ci.org/voku/simple-cache.svg?branch=master)](https://travis-ci.org/voku/simple-cache)\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fvoku%2Fsimple-cache.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fvoku%2Fsimple-cache?ref=badge_shield)\n[![Coverage Status](https://coveralls.io/repos/github/voku/simple-cache/badge.svg?branch=master)](https://coveralls.io/github/voku/simple-cache?branch=master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/voku/simple-cache/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/voku/simple-cache/?branch=master)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/5846d2a46599486486b3956c0ce11a18)](https://www.codacy.com/app/voku/simple-cache)\n[![Latest Stable Version](https://poser.pugx.org/voku/simple-cache/v/stable)](https://packagist.org/packages/voku/simple-cache) \n[![Total Downloads](https://poser.pugx.org/voku/simple-cache/downloads)](https://packagist.org/packages/voku/simple-cache) \n[![License](https://poser.pugx.org/voku/simple-cache/license)](https://packagist.org/packages/voku/simple-cache)\n[![Donate to this project using Paypal](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.me/moelleken)\n[![Donate to this project using Patreon](https://img.shields.io/badge/patreon-donate-yellow.svg)](https://www.patreon.com/voku)\n\n# :zap: Simple Cache Class\n\nThis is a simple Cache Abstraction Layer for PHP \u003e= 7.0 that provides a simple interaction \nwith your cache-server. You can define the Adapter / Serializer in the \"constructor\" or the class will auto-detect you server-cache in this order:\n\n1. Memcached / Memcache\n2. Redis\n3. Xcache\n4. APC / APCu\n5. OpCache (via PHP-files)\n6. Static-PHP-Cache\n\n### Get \"Simple Cache\"\n\nYou can download it from here, or require it using [composer](https://packagist.org/packages/voku/simple-cache).\n```json\n{\n  \"require\": {\n    \"voku/simple-cache\": \"4.*\"\n  }\n}\n```\n\n\n### Install via \"composer require\"\n\n```shell\ncomposer require voku/simple-cache\n```\n\n\n### Quick Start\n\n```php\nuse voku\\cache\\Cache;\n\nrequire_once 'composer/autoload.php';\n\n$cache = new Cache();\n$ttl = 3600; // 60s * 60 = 1h\n$cache-\u003esetItem('foo', 'bar', $ttl);\n$bar = $cache-\u003egetItem('foo');\n```\n\n\n### Usage \n\n```php\nuse voku\\cache\\Cache;\n\n$cache = new Cache();\n  \nif ($cache-\u003egetCacheIsReady() === true \u0026\u0026 $cache-\u003eexistsItem('foo')) {\n  return $cache-\u003egetItem('foo');\n} else {\n  $bar = someSpecialFunctionsWithAReturnValue();\n  $cache-\u003esetItem('foo', $bar);\n  return $bar;\n}\n```\n\nIf you have an heavy task e.g. a really-big-loop, then you can also use static-cache. \nBut keep in mind, that this will be stored into PHP (it needs more memory).\n\n```php\nuse voku\\cache\\Cache;\n\n$cache = new Cache();\n  \nif ($cache-\u003egetCacheIsReady() === true \u0026\u0026 $cache-\u003eexistsItem('foo')) {\n  for ($i = 0; $i \u003c= 100000; $i++) {\n    echo $this-\u003ecache-\u003egetItem('foo', 3); // use also static-php-cache, when we hit the cache 3-times\n  }\n  return $cache-\u003egetItem('foo');\n} else {\n  $bar = someSpecialFunctionsWithAReturnValue();\n  $cache-\u003esetItem('foo', $bar);\n  return $bar;\n}\n```\n\nPS: By default, the static cache is also used by \u003e= 10 cache hits. But you can configure \nthis behavior via $cache-\u003esetStaticCacheHitCounter(INT).\n\n## No-Cache for the admin or a specific ip-address\n\nIf you use the parameter \"$checkForUser\" (=== true) in the constructor, then the cache isn't used for the admin-session.\n\n-\u003e You can also overwrite the check for the user, if you add a global function named \"checkForDev()\".\n\n## Overwrite the auto-connection option\n\nYou can overwrite the cache auto-detect via \"CacheAdapterAutoManager\" and the \n\"$cacheAdapterManagerForAutoConnect\" option in the \"Cache\"-constructor. Additional you can also \nactivate the \"$cacheAdapterManagerForAutoConnectOverwrite\" option in the \"Cache\"-constructor, so that \nyou can implement your own cache auto-detect logic.\n\n```php\n\n$cacheManager = new \\voku\\cache\\CacheAdapterAutoManager();\n\n// 1. check for \"APCu\" support first\n$cacheManager-\u003eaddAdapter(\n    \\voku\\cache\\AdapterApcu::class\n);\n\n// 2. check for \"APC\" support\n$cacheManager-\u003eaddAdapter(\n    \\voku\\cache\\AdapterApcu::class\n);\n\n// 3. try \"OpCache\"-Cache\n$cacheManager-\u003eaddAdapter(\n    \\voku\\cache\\AdapterOpCache::class,\n    static function () {\n        $cacheDir = \\realpath(\\sys_get_temp_dir()) . '/simple_php_cache_opcache';\n\n        return $cacheDir;\n    }\n);\n\n// 4. try \"File\"-Cache\n$cacheManager-\u003eaddAdapter(\n    \\voku\\cache\\AdapterFileSimple::class,\n    static function () {\n        $cacheDir = \\realpath(\\sys_get_temp_dir()) . '/simple_php_cache_file';\n\n        return $cacheDir;\n    }\n);\n\n\n// 5. use Memory Cache as final fallback\n$cacheManager-\u003eaddAdapter(\n    \\voku\\cache\\AdapterArray::class\n);\n\n$cache = new \\voku\\cache\\CachePsr16(\n    null, // use auto-detection\n    null, // use auto-detection\n    false, // do not check for usage\n    true, // enable the cache\n    false, // do not check for admin session\n    false, // do not check for dev\n    false, // do not check for admin session\n    false, // do not check for server vs. client ip\n    '', // do not use \"_GET\"-parameter for disabling\n    $cacheManager, // new auto-detection logic\n    true // overwrite the auto-detection logic\n);\n```\n\n### Support\n\nFor support and donations please visit [Github](https://github.com/voku/simple-cache/) | [Issues](https://github.com/voku/simple-cache/issues) | [PayPal](https://paypal.me/moelleken) | [Patreon](https://www.patreon.com/voku).\n\nFor status updates and release announcements please visit [Releases](https://github.com/voku/simple-cache/releases) | [Twitter](https://twitter.com/suckup_de) | [Patreon](https://www.patreon.com/voku/posts).\n\nFor professional support please contact [me](https://about.me/voku).\n\n### Thanks\n\n- Thanks to [GitHub](https://github.com) (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc.\n- Thanks to [IntelliJ](https://www.jetbrains.com) as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!\n- Thanks to [Travis CI](https://travis-ci.com/) for being the most awesome, easiest continous integration tool out there!\n- Thanks to [StyleCI](https://styleci.io/) for the simple but powerfull code style check.\n- Thanks to [PHPStan](https://github.com/phpstan/phpstan) \u0026\u0026 [Psalm](https://github.com/vimeo/psalm) for relly great Static analysis tools and for discover bugs in the code!\n\n\n### License\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fvoku%2Fsimple-cache.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fvoku%2Fsimple-cache?ref=badge_large)\n","funding_links":["https://github.com/sponsors/voku","https://patreon.com/voku","https://tidelift.com/funding/github/packagist/voku/simple-cache","https://www.paypal.me/moelleken","https://www.patreon.com/voku","https://paypal.me/moelleken","https://www.patreon.com/voku/posts"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoku%2Fsimple-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvoku%2Fsimple-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoku%2Fsimple-cache/lists"}