{"id":17061786,"url":"https://github.com/phlak/stash","last_synced_at":"2025-10-17T00:32:40.469Z","repository":{"id":6898877,"uuid":"55566401","full_name":"PHLAK/Stash","owner":"PHLAK","description":"Simple PHP caching library","archived":false,"fork":false,"pushed_at":"2023-02-01T11:00:44.000Z","size":486,"stargazers_count":7,"open_issues_count":6,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T12:46:41.087Z","etag":null,"topics":["apcu","caching","file-cache","memcached","php","redis"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/phlak/stash","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/PHLAK.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"PHLAK","patreon":"PHLAK","custom":"https://paypal.me/ChrisKankiewicz"}},"created_at":"2016-04-06T01:17:16.000Z","updated_at":"2024-06-26T09:29:33.000Z","dependencies_parsed_at":"2023-02-17T04:45:32.435Z","dependency_job_id":null,"html_url":"https://github.com/PHLAK/Stash","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHLAK%2FStash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHLAK%2FStash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHLAK%2FStash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHLAK%2FStash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PHLAK","download_url":"https://codeload.github.com/PHLAK/Stash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248611838,"owners_count":21133183,"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":["apcu","caching","file-cache","memcached","php","redis"],"created_at":"2024-10-14T10:48:11.252Z","updated_at":"2025-10-17T00:32:40.463Z","avatar_url":"https://github.com/PHLAK.png","language":"PHP","funding_links":["https://github.com/sponsors/PHLAK","https://patreon.com/PHLAK","https://paypal.me/ChrisKankiewicz"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"stash.png\" alt=\"Stash\" width=\"60%\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    Lightweight PHP caching library • Created by \u003ca href=\"https://www.ChrisKankiewicz.com\"\u003eChris Kankiewicz\u003c/a\u003e (\u003ca href=\"https://bsky.app/profile/phlak.dev\"\u003e@PHLAK.dev\u003c/a\u003e)\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/PHLAK/Stash/discussions\"\u003e\u003cimg src=\"https://img.shields.io/badge/Join_the-Community-7b16ff.svg?style=for-the-badge\" alt=\"Join our Community\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/users/PHLAK/sponsorship\"\u003e\u003cimg src=\"https://img.shields.io/badge/Become_a-Sponsor-cc4195.svg?style=for-the-badge\" alt=\"Become a Sponsor\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://paypal.me/ChrisKankiewicz\"\u003e\u003cimg src=\"https://img.shields.io/badge/Make_a-Donation-006bb6.svg?style=for-the-badge\" alt=\"One-time Donation\"\u003e\u003c/a\u003e\n    \u003cbr\u003e\n    \u003ca href=\"https://packagist.org/packages/PHLAK/Stash\"\u003e\u003cimg src=\"https://img.shields.io/packagist/v/PHLAK/Stash.svg?style=flat-square\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/PHLAK/Stash\"\u003e\u003cimg src=\"https://img.shields.io/packagist/dt/PHLAK/Stash.svg?style=flat-square\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/PHLAK/Stash\"\u003e\u003cimg src=\"https://img.shields.io/packagist/l/PHLAK/Stash.svg?style=flat-square\" alt=\"License\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/PHLAK/Stash/actions\"\u003e\u003cimg alt=\"GitHub branch checks state\" src=\"https://img.shields.io/github/checks-status/PHLAK/Stash/master?style=flat-square\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n--- \n\nIntroduction\n------------\n\nStash is a lightweight PHP caching library supporting multiple, interchangeable\ncaching back-ends and an expressive (Laravel inspired) API.\n\nSupported caching back-ends:\n\n  - **File** - File-based caching. Stores cache items as files in a directory on disk.\n  - **Memcached** - High-performance, distributed memory object caching system\n  - **Redis** - In-memory data structure store.\n  - **APCu** - PHP's native APC User Cache.\n  - **Ephemeral** - A transient, in-memory array that only exists for the lifetime of the script.\n\nRequirements\n------------\n\n  - [PHP](https://php.net) \u003e= 8.1\n\nInstall with Composer\n---------------------\n\n```bash\ncomposer require phlak/stash\n```\n\nInitializing the Client\n-----------------------\n\nFirst, import Stash:\n\n```php\nuse PHLAK\\Stash;\n```\n\nThen instantiate Stash for your back-end of choice with the named constructor:\n\n```php\n$stash = Stash\\Cache::file($config);\n$stash = Stash\\Cache::memcached($config);\n$stash = Stash\\Cache::redis($config);\n$stash = Stash\\Cache::apcu($config);\n$stash = Stash\\Cache::ephemeral();\n```\n\nThe `$config` parameter accepts a driver-specific [closure](https://secure.php.net/manual/en/class.closure.php)\nfor setting configuration options for your chosen driver. Refer to the specific\ndocumentation about each driver below for more info. Not all drivers require a\nconfiguration function.\n\n----\n\n#### File Cache\n\nThe file cache configuration closure must call `$this-\u003esetCacheDir($path)` where\n`$path` is a path to a valid directory in which your cache files will be stored.\n\n```php\n$stash = Stash\\Cache::file(function (): void {\n    $this-\u003esetCacheDir('path/to/cache');\n});\n```\n\n#### Memcached\n\nThe Memcached configuration closure receives an instance of the\n[Memcached object](https://www.php.net/manual/en/class.memcached.php) as it's\nonly parameter, you can use this parameter to connect and configure Memcached.\nAt a minimum you must connect to one or more Memcached servers via the\n`addServer()` or `addServers()` methods.\n\nReference the [PHP Memcached documentation](https://secure.php.net/manual/en/book.memcached.php)\nfor additional configuration options.\n\n```php\n$stash = Stash\\Cache::memcached(function (Memcached $memcached): void {\n    $memcached-\u003eaddServer('localhost', 11211);\n    // $memcached-\u003esetOption(Memcached::OPT_PREFIX_KEY, 'some_prefix');\n});\n```\n\n#### Redis\n\nThe Redis configuration closure receives an instance of the\n[Redis object](https://github.com/phpredis/phpredis#class-redis) as it's only\nparameter, you can use this parameter to connect to and configure Redis. At a\nminimum you must connect to one or more Redis servers via the `connect()` or\n`pconnect()` methods.\n\nReference the [phpredis documentation](https://github.com/phpredis/phpredis#readme)\nfor additional configuration options.\n\n```php\n$stash = Stash\\Cache::redis(function (Redis $redis): void {\n    $redis-\u003epconnect('localhost', 6379);\n    // $redis-\u003esetOption(Redis::OPT_PREFIX, 'some_prefix');\n});\n```\n\n#### APCu\n\nThe APCu driver caches items in PHPs APC user cache.\n\n```php\n$stash = Stash\\Cache::apcu();\n```\n\nThe APCu driver does not require a configuration closure. However, if you\nwish to set a cache prefix you may pass a configuration closure that calls\n`$this-\u003esetPrefix($prefix)` where `$prefix` is a string of your desired prefix.\n\n```php\n$stash = Stash\\Cache::apcu(function (): void {\n    $this-\u003esetPrefix('some_prefix');\n});\n```\n\n#### Ephemeral\n\nThe Ephemeral driver caches items in a PHP array that exists in memory only for\nthe lifetime of the script. The Ephemeral driver does not take a configuration\nclosure.\n\n```php\n$stash = Stash\\Cache::ephemeral();\n```\n\nUsage\n-----\n\n### `Cacheable::put( string $key , mixed $data [, $ttl = 0 ] ) : bool`\n\nAdd an item to the cache for a specified duration.\n\n##### Examples\n\n```php\n// Cache a value for 5 minutes\n$stash-\u003eput('foo', 'some value', 300);\n\n// Cache a value indefinitely\n$stash-\u003eput('bar', false);\n```\n\n---\n\n### `Cacheable::forever( string $key , mixed $data) : bool`\n\nAdd an item to the cache permanently.\n\n##### Examples\n\n```php\n$stash-\u003eforever('foo', 'some value');\n```\n\n---\n\n### `Cacheable::get( string $key [, $default = false ] ) : mixed`\n\nRetrieve an item from the cache.\n\n##### Examples\n\n```php\n$stash-\u003eget('foo');\n\n// Return 'default' if 'bar' doesn't exist\n$stash-\u003eget('bar', 'default');\n```\n\n---\n### `Cacheable::has( string $key ) : bool`\n\nCheck if an item exists in the cache.\n\n##### Examples\n\n```php\n$stash-\u003ehas('foo');\n```\n\n---\n\n### `Cacheable::remember( string $key , int $ttl , Closure $closure ) : mixed`\n\nRetrieve item from cache or, when item does not exist, execute a closure. The\nresult of the closure is then stored in the cache for the specified duration\nand returned for immediate use.\n\n##### Examples\n\n```php\n$stash-\u003eremember('foo', 60, function() {\n    return new FooClass();\n});\n```\n\n---\n\n### `Cacheable::rememberForever( string $key , Closure $closure ) : mixed`\n\nRetrieve item from cache or, when item does not exist, execute a closure. The\nresult of the closure is then stored in the cache permanently.\n\n##### Examples\n\n```php\n$stash-\u003erememberForever('pokemon', function() {\n    return new Pokemon($name, $description);\n});\n```\n\n---\n\n### `Cacheable::increment( string $key [, int $value = 1 ] ) : mixed`\n\nIncrement an integer already stored in the cache.\n\n##### Examples\n\n```php\n// Increment by 1\n$stash-\u003eincrement('foo');\n\n// Increment by 10\n$stash-\u003eincrement('bar', 10);\n```\n\n---\n\n### `Cacheable::decrement( string $key [, int $value = 1 ] ) : mixed`\n\nDecrement an integer already stored in the cache.\n\n##### Examples\n\n```php\n // Decrements by 1\n$stash-\u003edecrement('foo');\n\n // Decrements by 10\n$stash-\u003edecrement('bar', 10);\n```\n\n---\n\n### `Cacheable::touch( string|array $key [, int $ttl = 0 ] ) : bool`\n\nExtend the expiration time for an item in the cache.\n\n##### Examples\n\n```php\n // Extend the expiration by 5 minutes\n$stash-\u003etouch('foo', 300);\n\n // Extend the expiration indefinitely\n$stash-\u003etouch('bar');\n\n// Extend the expiration of multiple items by 5 minutes\n$stash-\u003etouch(['foo', 'bar', 'baz'], 300);\n```\n\n---\n\n### `Cacheable::forget( string $key ) : bool`\n\nRemove an item from the cache.\n\n##### Examples\n\n```php\n$stash-\u003eforget('foo');\n```\n\n---\n\n### `Cacheable::flush() : bool`\n\nDelete all items from the cache.\n\n##### Examples\n\n```php\n$stash-\u003eflush();\n```\n\nTTL Helper\n---------------------\n\nFor convenience, Stash provides a `TTL` helper class to convert units of time to\nseconds. This is useful for setting the `$ttl` parameter in various methods.\n\n##### Examples\n\n```php\nuse PHLAK\\Stash\\TTL;\n\n// Cache a value for 5 minutes\n$stash-\u003eput('foo', 'some value', TTL::minutes(5));\n\n// Remember an item for one day\n$stash-\u003eremember('bar', TTL::days(1), fn (): string =\u003e 'Some value');\n\n// Update the expiration time of an item to 3 hour\n$stash-\u003etouch('baz', TTL::hours(3));\n```\n\nChangelog\n---------\n\nA list of changes can be found on the [GitHub Releases](https://github.com/PHLAK/Stash/releases) page.\n\nTroubleshooting\n---------------\n\nFor general help and support join our [GitHub Discussions](https://github.com/PHLAK/Stash/discussions) or reach out on [Bluesky](https://bsky.app/profile/phlak.dev).\n\nPlease report bugs to the [GitHub Issue Tracker](https://github.com/PHLAK/Stash/issues).\n\nCopyright\n---------\n\nThis project is licensed under the [MIT License](https://github.com/PHLAK/Stash/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphlak%2Fstash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphlak%2Fstash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphlak%2Fstash/lists"}