Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

Media24si/ResponseCache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Response cache

Software License Build Status

Laravel 5 response cache.

Install

Require this package with Composer (Packagist), using the following command:

$ composer require media24si/response-cache

Register the ResponseCacheServiceProvider to the providers array in config/app.php

Media24si\ResponseCache\ResponseCacheServiceProvider::class

Publish vendor files (config file):

$ php artisan vendor:publish

To access cache manager register facade in config/app.php

'ResponseCacheManager' => Media24si\ResponseCache\Facades\ResponseCacheManagerFacade::class

Usage

Register middleware as a global in app/Http/Kernel.php

\Media24si\ResponseCache\Http\Middleware\CacheMiddleware::class

To cache response, mark response as public and set max-age (TTL):

return response()->json(['name' => 'John'])
		->setPublic()
		->setMaxAge(600);

Tag usage

Many times you want to assing tags to URI. With assigned tags it's simple to clear more cached URIs.

To assign tag to caching response, set cache-tags header. To assign more tags, seperate them with comma (,).

To cache response, mark response as public and set max-age (TTL):

return response()->json(['name' => 'John'])
		->setPublic()
		->setMaxAge(600)
		->header('cache-tags', 'foo,bar,john,doe');

To flush all keys for tag:

ResponseCacheManager::flushTag('foo')

Config

Check responseCache.php for all possible configurations.

License

The MIT License (MIT). Please see License File for more information.

About

Laravel 5 response cache

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages