{"id":15673553,"url":"https://github.com/lmammino/guzzle-apcu-fs-cache","last_synced_at":"2025-05-06T22:41:41.506Z","repository":{"id":38160871,"uuid":"252156329","full_name":"lmammino/guzzle-apcu-fs-cache","owner":"lmammino","description":"A zero config cache storage for guzzle-cache-middleware that tries to cache on Apcu and fallbacks to filesystem","archived":false,"fork":false,"pushed_at":"2023-04-19T19:31:35.000Z","size":42,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T03:41:18.497Z","etag":null,"topics":["apcu","cache","cache-storage","filesystem","guzzle","http","middleware","php"],"latest_commit_sha":null,"homepage":null,"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/lmammino.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":"2020-04-01T11:32:29.000Z","updated_at":"2020-04-26T00:19:35.000Z","dependencies_parsed_at":"2024-10-23T11:25:19.991Z","dependency_job_id":null,"html_url":"https://github.com/lmammino/guzzle-apcu-fs-cache","commit_stats":{"total_commits":8,"total_committers":1,"mean_commits":8.0,"dds":0.0,"last_synced_commit":"00b37ebbc4d58598b38aa8a0ff8b5005477f2a4a"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fguzzle-apcu-fs-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fguzzle-apcu-fs-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fguzzle-apcu-fs-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fguzzle-apcu-fs-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lmammino","download_url":"https://codeload.github.com/lmammino/guzzle-apcu-fs-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252782436,"owners_count":21803378,"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","cache","cache-storage","filesystem","guzzle","http","middleware","php"],"created_at":"2024-10-03T15:41:14.784Z","updated_at":"2025-05-06T22:41:41.477Z","avatar_url":"https://github.com/lmammino.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# guzzle-apcu-fs-cache\n\nA zero config cache storage for guzzle-cache-middleware that tries to cache on Apcu and fallbacks to filesystem.\n\n![Tests](https://github.com/lmammino/guzzle-apcu-fs-cache/workflows/Tests/badge.svg)\n[![Latest Stable Version](https://poser.pugx.org/lmammino/guzzle-apcu-fs-cache/v/stable?)](https://packagist.org/packages/lmammino/guzzle-apcu-fs-cache)\n[![Total Downloads](https://poser.pugx.org/lmammino/guzzle-apcu-fs-cache/downloads?)](https://packagist.org/packages/lmammino/guzzle-apcu-fs-cache)\n[![Latest Unstable Version](https://poser.pugx.org/lmammino/guzzle-apcu-fs-cache/v/unstable?)](https://packagist.org/packages/lmammino/guzzle-apcu-fs-cache)\n[![License](https://poser.pugx.org/lmammino/guzzle-apcu-fs-cache/license?)](https://packagist.org/packages/lmammino/guzzle-apcu-fs-cache)\n[![composer.lock](https://poser.pugx.org/lmammino/guzzle-apcu-fs-cache/composerlock?)](https://packagist.org/packages/lmammino/guzzle-apcu-fs-cache)\n\n\n## Install\n\nRequires PHP 5.5+.\n\nUsing composer:\n\n```bash\ncomposer require lmammino/guzzle-apcu-fs-cache\n```\n\n\n## Usage\n\nThis is an example of how you can use this storage engine with [Guzzle](https://guzzlephp.org) and [GuzzleCacheMiddleware](https://github.com/Kevinrob/guzzle-cache-middleware):\n\n```php\n\u003c?php\n\nrequire_once __DIR__.'/vendor/autoload.php';\n\nuse GuzzleHttp\\HandlerStack;\nuse GuzzleHttp\\Handler\\CurlHandler;\nuse GuzzleHttp\\Client;\nuse Kevinrob\\GuzzleCache\\CacheMiddleware;\nuse Kevinrob\\GuzzleCache\\Strategy\\PrivateCacheStrategy;\nuse LM\\GuzzleCache\\Storage\\ApcuFsStorage;\n\n// creates the storage (with default options)\n$cacheStorage = new ApcuFsStorage();\n\n// creates the cache middleware\n$cacheMiddleware = new CacheMiddleware(\n    new PrivateCacheStrategy($cacheStorage)\n);\n\n// creates a Guzzle client middleware stack\n$stack = new HandlerStack();\n$stack-\u003esetHandler(new CurlHandler());\n$stack-\u003epush($cacheMiddleware, 'cache');\n$client = new Client(['handler' =\u003e $stack]);\n\n// make a request\n$res = $client-\u003erequest('GET', 'https://loige.co/');\n// print response headers\n$headers = $res-\u003egetHeaders();\nforeach ($headers as  $k =\u003e $h) {\n    foreach ($h as $v) {\n        echo $k . \": \" . $v . \"\\n\";\n    }\n}\n// print response body\necho \"\\n\\n\" . $res-\u003egetBody()-\u003e__toString() . \"\\n\\n\";\n```\n\n### Use with Launch Darkly PHP SDK\n\nIf you want to use this cache storage with the [Launch Darkly PHP SDK](https://docs.launchdarkly.com/sdk/server-side/php), here's how you can do it:\n\n```php\n\u003c?php\n\nrequire_once __DIR__.'/vendor/autoload.php';\n\nuse LaunchDarkly\\LDClient;\nuse LaunchDarkly\\LDUser;\nuse LM\\GuzzleCache\\Storage\\ApcuFsStorage;\n\n$cacheStorage = new ApcuFsStorage();\n$LDClient = new LDClient($ldSDKKey, [\"cache\" =\u003e $cacheStorage]);\n$LDUser = new LDUser(\"test@example.com\");\n\n// use the client\nvar_dump($LDClient-\u003evariation('some-flag', $LDUser));\n```\n\n\n## Configuration\n\nThe storage layer can be configured at construction time.\n\nThese are the following parameters accepted by the constructor:\n\n - (string) `$dir`: The directory where the cache should be saved if using the filesystem (Default: the temp directory).\n - (string) `$namespace`: A namespace for the cache storage, useful when using multiple instances and cache should not be mixed between them. It will create a subfolder on the filesystme and a prefix on APC. (Default: `'default'`).\n - (integer) `$ttl` The duration of a cache entry in seconds (Default: `60`).\n - (callable) `$onHit` An optional function that gets called when there's a cache hit.\n - (callable) `$onMiss` An optional function that gets called when there's a cache miss.\n\nIf you want to inspect whether your current instance is using APC or the filesystem you can use the following public properties:\n\n - `$storage-\u003eusingApcu` (returns `true` or `false`)\n - `$storage-\u003eusingFilesystem` (returns `true` or `false`)\n\n\n## Rationale and Notes\n\nThis was originally created to cache requests made by the Launch Darkly client in a more controlled and configurable way.\n\n**Note**: this middleware will always respect the TTL you provide and will ignore any HTTP cache header returned as response. This is by design. Use this middleware only if you want to enforce cache or for micro-caching scenarios (e.g. very expensive and frequent API calls).\n\n\n## Contributing\n\nEveryone is very welcome to contribute to this project.\nYou can contribute just by submitting bugs or suggesting improvements by\n[opening an issue on GitHub](https://github.com/lmammino/guzzle-apcu-fs-cache/issues).\n\n\n## License\n\nLicensed under [MIT License](LICENSE). © Luciano Mammino.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmammino%2Fguzzle-apcu-fs-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flmammino%2Fguzzle-apcu-fs-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmammino%2Fguzzle-apcu-fs-cache/lists"}