{"id":21467397,"url":"https://github.com/elusivecodes/fyrecache","last_synced_at":"2025-07-15T05:31:20.510Z","repository":{"id":62508427,"uuid":"423098914","full_name":"elusivecodes/FyreCache","owner":"elusivecodes","description":"FyreCache is a free, open-source cache library for PHP.","archived":false,"fork":false,"pushed_at":"2024-11-15T10:30:10.000Z","size":134,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-15T11:28:53.343Z","etag":null,"topics":["cache","memcached","php","redis"],"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/elusivecodes.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":"2021-10-31T09:01:30.000Z","updated_at":"2024-11-15T10:29:57.000Z","dependencies_parsed_at":"2024-06-01T17:12:48.480Z","dependency_job_id":"ddcd3a9c-3214-4a7f-8a7a-c52527c7b83d","html_url":"https://github.com/elusivecodes/FyreCache","commit_stats":null,"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreCache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreCache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreCache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreCache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elusivecodes","download_url":"https://codeload.github.com/elusivecodes/FyreCache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226017461,"owners_count":17560514,"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","memcached","php","redis"],"created_at":"2024-11-23T08:17:51.857Z","updated_at":"2025-07-15T05:31:20.497Z","avatar_url":"https://github.com/elusivecodes.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FyreCache\r\n\r\n**FyreCache** is a free, open-source cache library for *PHP*.\r\n\r\n\r\n## Table Of Contents\r\n- [Installation](#installation)\r\n- [Basic Usage](#basic-usage)\r\n- [Methods](#methods)\r\n- [Cachers](#cachers)\r\n    - [File](#file)\r\n    - [Memcached](#memcached)\r\n    - [Redis](#redis)\r\n\r\n\r\n\r\n## Installation\r\n\r\n**Using Composer**\r\n\r\n```\r\ncomposer require fyre/cache\r\n```\r\n\r\nIn PHP:\r\n\r\n```php\r\nuse Fyre\\Cache\\CacheManager;\r\n```\r\n\r\n\r\n## Basic Usage\r\n\r\n- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n- `$config` is a  [*Config*](https://github.com/elusivecodes/FyreConfig).\r\n\r\n```php\r\n$cacheManager = new CacheManager($container);\r\n```\r\n\r\nDefault configuration options will be resolved from the \"*Cache*\" key in the [*Config*](https://github.com/elusivecodes/FyreConfig).\r\n\r\nThe cache will be disabled by default if the `\"*App.debug*\" key is set in the [*Config*](https://github.com/elusivecodes/FyreConfig).\r\n\r\n**Autoloading**\r\n\r\nIt is recommended to bind the *CacheManager* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.\r\n\r\n```php\r\n$container-\u003esingleton(CacheManager::class);\r\n```\r\n\r\nAny dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n```php\r\n$cacheManager = $container-\u003euse(CacheManager::class);\r\n```\r\n\r\n\r\n## Methods\r\n\r\n**Build**\r\n\r\nBuild a [*Cacher*](#cachers).\r\n\r\n- `$options` is an array containing configuration options.\r\n\r\n```php\r\n$cacher = $cacheManager-\u003ebuild($options);\r\n```\r\n\r\n[*Cacher*](#cachers) dependencies will be resolved automatically from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n**Clear**\r\n\r\nClear all instances and configs.\r\n\r\n```php\r\n$cacheManager-\u003eclear();\r\n```\r\n\r\n**Disable**\r\n\r\nDisable the cache.\r\n\r\n```php\r\n$cacheManager-\u003edisable();\r\n```\r\nIf the cache is disabled, the `use` method will always return a *NullCacher*.\r\n\r\n**Enable**\r\n\r\nEnable the cache.\r\n\r\n```php\r\n$cacheManager-\u003eenable();\r\n```\r\n\r\n**Get Config**\r\n\r\nGet a [*Cacher*](#cachers) config.\r\n\r\n- `$key` is a string representing the [*Cacher*](#cachers) key.\r\n\r\n```php\r\n$config = $cacheManager-\u003egetConfig($key);\r\n```\r\n\r\nAlternatively, if the `$key` argument is omitted an array containing all configurations will be returned.\r\n\r\n```php\r\n$config = $cacheManager-\u003egetConfig();\r\n```\r\n\r\n**Has Config**\r\n\r\nDetermine whether a [*Cacher*](#cachers) config exists.\r\n\r\n- `$key` is a string representing the [*Cacher*](#cachers) key, and will default to `CacheManager::DEFAULT`.\r\n\r\n```php\r\n$hasConfig = $cacheManager-\u003ehasConfig($key);\r\n```\r\n\r\n**Is Enabled**\r\n\r\nDetermine whether the cache is enabled.\r\n\r\n```php\r\n$cacheManager-\u003eisEnabled();\r\n```\r\n\r\n**Is Loaded**\r\n\r\nDetermine whether a [*Cacher*](#cachers) instance is loaded.\r\n\r\n- `$key` is a string representing the [*Cacher*](#cachers) key, and will default to `CacheManager::DEFAULT`.\r\n\r\n```php\r\n$isLoaded = $cacheManager-\u003eisLoaded($key);\r\n```\r\n\r\n**Set Config**\r\n\r\nSet the [*Cacher*](#cachers) config.\r\n\r\n- `$key` is a string representing the [*Cacher*](#cachers) key.\r\n- `$options` is an array containing configuration options.\r\n\r\n```php\r\n$cacheManager-\u003esetConfig($key, $options);\r\n```\r\n\r\n**Unload**\r\n\r\nUnload a [*Cacher*](#cachers).\r\n\r\n- `$key` is a string representing the [*Cacher*](#cachers) key, and will default to `CacheManager::DEFAULT`.\r\n\r\n```php\r\n$cacheManager-\u003eunload($key);\r\n```\r\n\r\n**Use**\r\n\r\nLoad a shared [*Cacher*](#cachers) instance.\r\n\r\n- `$key` is a string representing the [*Cacher*](#cachers) key, and will default to `CacheManager::DEFAULT`.\r\n\r\n```php\r\n$cacher = $cacheManager-\u003euse($key);\r\n```\r\n\r\n[*Cacher*](#cachers) dependencies will be resolved automatically from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n\r\n## Cachers\r\n\r\nYou can load a specific cacher by specifying the `className` option of the `$options` variable above.\r\n\r\nCustom cachers can be created by extending `\\Fyre\\Cache\\Cacher`, ensuring all below methods are implemented.\r\n\r\n**Decrement**\r\n\r\nDecrement a cache value.\r\n\r\n- `$key` is a string representing the cache key.\r\n- `$amount` is a number indicating the amount to decrement by, and will default to *1*.\r\n\r\n```php\r\n$value = $cacher-\u003edecrement($key, $amount);\r\n```\r\n\r\n**Delete**\r\n\r\nDelete an item from the cache.\r\n\r\n- `$key` is a string representing the cache key.\r\n\r\n```php\r\n$deleted = $cacher-\u003edelete($key);\r\n```\r\n\r\n**Empty**\r\n\r\nEmpty the cache.\r\n\r\n```php\r\n$emptied = $cacher-\u003eempty();\r\n```\r\n\r\n**Get**\r\n\r\nRetrieve a value from the cache.\r\n\r\n- `$key` is a string representing the cache key.\r\n\r\n```php\r\n$value = $cacher-\u003eget($key);\r\n```\r\n\r\n**Has**\r\n\r\nDetermine whether an item exists in the cache.\r\n\r\n- `$key` is a string representing the cache key.\r\n\r\n```php\r\n$has = $cacher-\u003ehas($key);\r\n```\r\n\r\n**Increment**\r\n\r\nIncrement a cache value.\r\n\r\n- `$key` is a string representing the cache key.\r\n- `$amount` is a number indicating the amount to increment by, and will default to *1*.\r\n\r\n```php\r\n$value = $cacher-\u003eincrement($key, $amount);\r\n```\r\n\r\n**Remember**\r\n\r\nRetrieve an item from the cache, or save a new value if it doesn't exist.\r\n\r\n- `$key` is a string representing the cache key.\r\n- `$callback` is the callback method to generate the value.\r\n- `$expire` is a number indicating the number of seconds the value will be valid, and will default to *null*.\r\n\r\n```php\r\n$value = $cacher-\u003eremember($key, $callback, $expire);\r\n```\r\n\r\n**Save**\r\n\r\nSave an item in the cache.\r\n\r\n- `$key` is a string representing the cache key.\r\n- `$value` is the value to save in the cache.\r\n- `$expire` is a number indicating the number of seconds the value will be valid, and will default to *null*.\r\n\r\n```php\r\n$saved = $cacher-\u003esave($key, $value, $expire);\r\n```\r\n\r\n**Size**\r\n\r\nGet the size of the cache.\r\n\r\n```php\r\n$size = $cacher-\u003esize();\r\n```\r\n\r\n\r\n## Array\r\n\r\nThe Array cacher can be loaded using customer configuration.\r\n\r\n- `$options` is an array containing configuration options.\r\n    - `className` must be set to `\\Fyre\\Cache\\Handlers\\ArrayCacher`.\r\n    - `expire` is a number indicating the default cache timeout.\r\n\r\n```php\r\n$container-\u003euse(Config::class)-\u003eset('Cache.array', $options);\r\n```\r\n\r\n\r\n### File\r\n\r\nThe File cacher can be loaded using custom configuration.\r\n\r\n- `$options` is an array containing configuration options.\r\n    - `className` must be set to `\\Fyre\\Cache\\Handlers\\FileCacher`.\r\n    - `expire` is a number indicating the default cache timeout.\r\n    - `prefix` is a string representing the cache key prefix.\r\n    - `path` is a string representing the directory path, and will default to \"*/tmp/cache*\".\r\n    - `mode` is a number indicating the cache file permissions, and will default to *0640*.\r\n\r\n```php\r\n$container-\u003euse(Config::class)-\u003eset('Cache.file', $options);\r\n```\r\n\r\n\r\n### Memcached\r\n\r\nThe Memcached cacher can be loaded using custom configuration.\r\n\r\n- `$options` is an array containing configuration options.\r\n    - `className` must be set to `\\Fyre\\Cache\\Handlers\\MemcachedCacher`.\r\n    - `expire` is a number indicating the default cache timeout.\r\n    - `prefix` is a string representing the cache key prefix.\r\n    - `host` is a string representing the Memcached host, and will default to \"*127.0.0.1*\".\r\n    - `port` is a number indicating the Memcached port, and will default to *11211*.\r\n    - `weight` is a number indicating the server weight, and will default to *1*.\r\n\r\n```php\r\n$container-\u003euse(Config::class)-\u003eset('Cache.memcached', $options);\r\n```\r\n\r\n\r\n### Redis\r\n\r\nThe Redis cacher can be loaded using custom configuration.\r\n\r\n- `$options` is an array containing configuration options.\r\n    - `className` must be set to `\\Fyre\\Cache\\Handlers\\RedisCacher`.\r\n    - `expire` is a number indicating the default cache timeout.\r\n    - `prefix` is a string representing the cache key prefix.\r\n    - `host` is a string representing the Redis host, and will default to \"*127.0.0.1*\".\r\n    - `password` is a string representing the Redis password.\r\n    - `port` is a number indicating the Redis port, and will default to *6379*.\r\n    - `database` is a string representing the Redis database.\r\n    - `timeout` is a number indicating the connection timeout.\r\n    - `persist` is a boolean indicating whether to use a persistent connection, and will default to *true*.\r\n    - `tls` is a boolean indicating whether to use a tls connection, and will default to *true*.\r\n    - `ssl` is an array containing SSL options.\r\n        - `key` is a string representing the path to the key file.\r\n        - `cert` is a string representing the path to the certificate file.\r\n        - `ca` is a string representing the path to the certificate authority file.\r\n\r\n```php\r\n$container-\u003euse(Config::class)-\u003eset('Cache.redis', $options);\r\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyrecache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felusivecodes%2Ffyrecache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyrecache/lists"}