Download the PHP package lmammino/guzzle-apcu-fs-cache without Composer
On this page you can find all versions of the php package lmammino/guzzle-apcu-fs-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lmammino/guzzle-apcu-fs-cache
More information about lmammino/guzzle-apcu-fs-cache
Files in lmammino/guzzle-apcu-fs-cache
Package guzzle-apcu-fs-cache
Short Description A zero config cache storage for guzzle-cache-middleware that tries to cache on Apcu and fallbacks to filesystem
License MIT
Informations about the package guzzle-apcu-fs-cache
guzzle-apcu-fs-cache
A zero config cache storage for guzzle-cache-middleware that tries to cache on Apcu and fallbacks to filesystem.
Install
Requires PHP 5.5+.
Using composer:
Usage
This is an example of how you can use this storage engine with Guzzle and GuzzleCacheMiddleware:
Use with Launch Darkly PHP SDK
If you want to use this cache storage with the Launch Darkly PHP SDK, here's how you can do it:
Configuration
The storage layer can be configured at construction time.
These are the following parameters accepted by the constructor:
- (string)
$dir
: The directory where the cache should be saved if using the filesystem (Default: the temp directory). - (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'
). - (integer)
$ttl
The duration of a cache entry in seconds (Default:60
). - (callable)
$onHit
An optional function that gets called when there's a cache hit. - (callable)
$onMiss
An optional function that gets called when there's a cache miss.
If you want to inspect whether your current instance is using APC or the filesystem you can use the following public properties:
$storage->usingApcu
(returnstrue
orfalse
)$storage->usingFilesystem
(returnstrue
orfalse
)
Rationale and Notes
This was originally created to cache requests made by the Launch Darkly client in a more controlled and configurable way.
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).
Contributing
Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub.
License
Licensed under MIT License. © Luciano Mammino.