{"id":17976067,"url":"https://github.com/stefangabos/zebra_cache","last_synced_at":"2025-10-25T07:31:13.245Z","repository":{"id":57749874,"uuid":"524972069","full_name":"stefangabos/Zebra_Cache","owner":"stefangabos","description":"A lightweight and flexible PHP caching library with support for file, Redis, and Memcached storage backends.","archived":false,"fork":false,"pushed_at":"2025-01-30T16:06:26.000Z","size":209,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-30T17:21:46.597Z","etag":null,"topics":["cache","cache-library","caching","memcache","memcached","performance","php","redis"],"latest_commit_sha":null,"homepage":"https://stefangabos.github.io/Zebra_Cache/Zebra_Cache/Zebra_Cache.html","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/stefangabos.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2022-08-15T12:07:02.000Z","updated_at":"2025-01-30T16:06:30.000Z","dependencies_parsed_at":"2024-06-09T09:51:35.021Z","dependency_job_id":"9b7000c8-8109-41c3-a841-79bf18aa0653","html_url":"https://github.com/stefangabos/Zebra_Cache","commit_stats":{"total_commits":55,"total_committers":1,"mean_commits":55.0,"dds":0.0,"last_synced_commit":"f86badf92f8a2b5e805e7ca0f2e95ba1471ffb3f"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefangabos%2FZebra_Cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefangabos%2FZebra_Cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefangabos%2FZebra_Cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefangabos%2FZebra_Cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stefangabos","download_url":"https://codeload.github.com/stefangabos/Zebra_Cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238101555,"owners_count":19416535,"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-library","caching","memcache","memcached","performance","php","redis"],"created_at":"2024-10-29T17:21:51.115Z","updated_at":"2025-10-25T07:31:13.233Z","avatar_url":"https://github.com/stefangabos.png","language":"PHP","readme":"\u003cimg src=\"https://github.com/stefangabos/zebrajs/blob/master/docs/images/logo.png\" alt=\"zebra-curl-logo\" align=\"right\" width=\"90\"\u003e\n\n# Zebra Cache \u0026nbsp;[![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=A+file-based+lightweight+PHP+caching+library+that+uses+file+locking+to+ensure+proper+functionality+under+heavy+load\u0026url=https://github.com/stefangabos/Zebra_Cache\u0026via=stefangabos\u0026hashtags=php,cache)\n\n*A lightweight and flexible PHP caching library with support for file, Redis, and Memcached storage backends.*\n\n[![Latest Stable Version](https://poser.pugx.org/stefangabos/zebra_cache/v/stable)](https://packagist.org/packages/stefangabos/zebra_cache) [![Total Downloads](https://poser.pugx.org/stefangabos/zebra_cache/downloads)](https://packagist.org/packages/stefangabos/zebra_cache) [![Monthly Downloads](https://poser.pugx.org/stefangabos/zebra_cache/d/monthly)](https://packagist.org/packages/stefangabos/zebra_cache) [![Daily Downloads](https://poser.pugx.org/stefangabos/zebra_cache/d/daily)](https://packagist.org/packages/stefangabos/zebra_cache) [![License](https://poser.pugx.org/stefangabos/zebra_cache/license)](https://packagist.org/packages/stefangabos/zebra_cache)\n\nThis library provides a unified interface for caching data, allowing the use of various storage backends like file-based caching, Redis, Memcached, or custom implementations.\n\nIt supports common caching operations such as storing, retrieving and deleting data, as well as checking for the existence of a cache entry.\n\n## Features\n\n- pluggable architecture for using different storage mechanisms\n- flexible key-value caching\n- automatic expiration of cache items based on a specified time-to-live (TTL) value\n- extensible design allowing developers to integrate new storage backends\n- easy-to-use API with consistent behavior across different backends\n- support for multiple instances, allowing you to use different cache configurations for different parts of your application\n\n## :notebook_with_decorative_cover: Documentation\n\nCheck out the [awesome documentation](https://stefangabos.github.io/Zebra_Cache/Zebra_Cache/Zebra_Cache.html)!\n\n## 🎂 Support the development of this project\n\nYour support is greatly appreciated and it keeps me motivated continue working on open source projects. If you enjoy this project please star it by clicking on the star button at the top of the page. If you're feeling generous, you can also buy me a coffee through PayPal or become a sponsor.\n**Thank you for your support!** 🎉\n\n[\u003cimg src=\"https://img.shields.io/github/stars/stefangabos/zebra_cache?color=green\u0026label=star%20it%20on%20GitHub\" width=\"132\" height=\"20\" alt=\"Star it on GitHub\"\u003e](https://github.com/stefangabos/Zebra_Cache) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=W6MCFT65DRN64) [\u003cimg src=\"https://img.shields.io/badge/-Sponsor-fafbfc?logo=GitHub%20Sponsors\"\u003e](https://github.com/sponsors/stefangabos)\n\n\n## Requirements\n\nPHP 7.0.0+\n\nUse version [1.3.2](https://github.com/stefangabos/Zebra_Cache/releases/tag/1.3.2) if you need support for PHP 5.3.0+\n\n## Installation\n\nInstall via [Composer](https://packagist.org/packages/stefangabos/zebra_cache)\n\n```bash\n# get the latest stable release\ncomposer require stefangabos/zebra_cache\n\n# get the latest commit\ncomposer require stefangabos/zebra_cache:dev-master\n```\n\n## Initializing the storage engine\n\nInitializing **file-based storage**:\n\n```php\n// make sure you have this at the top of your script\nuse stefangabos\\Zebra_Cache\\Zebra_Cache;\nuse stefangabos\\Zebra_Cache\\Storage\\Storage_File;\n\n// initialize file-based storage\n$storage = new Storage_File('/path/to/cache/folder');\n```\n\nInitializing **Redis-based storage**:\n\n```php\n// make sure you have this at the top of your script\nuse stefangabos\\Zebra_Cache\\Zebra_Cache;\nuse stefangabos\\Zebra_Cache\\Storage\\Storage_Redis;\n\n// connect to a Redis server\n$redis = new Redis();\n$redis-\u003econnect('127.0.0.1', 6379);\n\n// pass the $redis instance as argument to initialize the Redis-based storage\n$storage = new Storage_Redis($redis);\n\n// finally, instantiate the caching library using the storage engine configured above\n$cache = new stefangabos\\Zebra_Cache\\Zebra_Cache($storage);\n```\n\nInitializing **Memcached-based storage**:\n\nThere are two PHP extensions for working with [Memcached](https://memcached.org/): the [memcache](https://www.php.net/manual/en/book.memcache.php) extension, which is older and less commonly used, and [memcached](https://www.php.net/manual/en/book.memcached.php) which is generally preferred for better features and compatibility.\nThis library supports both.\n\n```php\n// make sure you have this at the top of your script\nuse stefangabos\\Zebra_Cache\\Zebra_Cache;\nuse stefangabos\\Zebra_Cache\\Storage\\Storage_Memcached;\n\n// connect to a Memcached server (using the `memcached` extension)\n$memcache = new Memcached();\n$memcache-\u003eaddServer('localhost', 11211);\n\n// OR using the `memcache` extension\n$memcache = new Memcache();\n$memcache-\u003eaddServer('localhost', 11211);\n\n// pass the $memcache instance as argument to initialize the Memcached-based storage\n$storage = new Storage_Memcached($memcache);\n```\n## Initializing the main library and setting/getting values\n\nOnce the storage engine is initialized:\n\n```php\n// instantiate the caching library using the chosen storage engine\n$cache = new Zebra_Cache($storage);\n\n// if a cached, non-expired value for the sought key does not exist\nif (!($my_data = $cache-\u003eget('my-key'))) {\n\n    // do whatever you need to retrieve data\n    $my_data = 'my data';\n\n    // cache the values for 10 minutes (10 x 60 seconds)\n    $cache-\u003eset('my-key', $my_data, 10 * 60);\n\n}\n\n// at this point $my_data will always contain data, either from cache, or fresh\n```\n\n### Getting information about cached data\n\n```php\nif ($info = $cache-\u003ehas('my-key')) {\n\n    print_r('\u003cpre\u003e');\n    print_r($info);\n\n    // for file-based storage the output will look something like\n    // [\n    //  'path'     =\u003e '',  //  path to the cache file\n    //  'timeout'  =\u003e '',  //  the number of seconds the cache was supposed to be valid\n    //  'ttl'      =\u003e '',  //  number of seconds remaining until the cache expires\n    // ]\n\n}\n```\n\n### Deleting cached data\n\n```php\n$cache-\u003edelete('my-key');\n```\n","funding_links":["https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=W6MCFT65DRN64","https://github.com/sponsors/stefangabos"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefangabos%2Fzebra_cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefangabos%2Fzebra_cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefangabos%2Fzebra_cache/lists"}