ordent / cache-url-redis
AIO Cache Management based on URL and Auth Implementation
v1.0.0
2020-08-22 11:36 UTC
Requires
- php: >=7.2
This package is auto-updated.
Last update: 2024-12-22 20:59:10 UTC
README
AIO cache management service based on URL and Auth JWT Implementation.
How To Use
- Install the package via composer
composer require ordent/cache-url-redis
- Implement the providers in your app configurations at
config/app.php
'providers' => [ Ordent\CacheURLRedis\Providers\URLCacheProvider::class ]
- Add a constant in the start of your
bootstart/app.php
to measure the execution time of your api.
define('EXEC_TIME_START', microtime(true));
- Add our middleware in
App\Http\Kernel
to short circuit the computation process to redis when the URL key is found.
protected $middleware = [ Ordent\CacheURLRedis\Middleware\URLCacheMiddleware::class ]
- Don't forget to set up your
CACHE
env implementation.
CACHE_DRIVER=redis
Output
- We measure and deliver the endpoint execution time via response header
X-Elapsed-Time
. - You need to send a Header in order to use the caching mechanism. If the header is not found on the request, the request will be computed normally. The header you need to set is
X-Cache-URL
with either value ofwith-auth
orwithout-auth
. - When the value
without-auth
is being used, the application will short circuit the computation process to Redis with finding the key of request URL. - However if the value
with-auth
is used, the application will use the Redis with key format :{application-url}:{authorization-header-value}
withauthorization-header-value
is your JWT token with Bearer format removed. - As of now the cache will last 60 minutes and won't cache another value unless you use header
X-Cache-URL-Invalidate
, you can use it to invalidate the cache value after transaction or any other database change.