2017 © Pedro Peláez
 

library result-cache

A simple and decoupled way to store resource consuming operations results in cache.

image

tequilarapido/result-cache

A simple and decoupled way to store resource consuming operations results in cache.

  • Wednesday, January 25, 2017
  • by nbourguig
  • Repository
  • 2 Watchers
  • 1 Stars
  • 22 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 16 % Grown

The README.md

A simple and decoupled way to store resource consuming operations results in cache., (*1)

Latest Version on Packagist Software License Build Status StyleCI SensioLabsInsight Quality Score Code Coverage, (*2)

Laravel Translation Sheet , (*3)

Contents

Installation

You can install the package using composer, (*4)

``` bash $ composer require tequilarapido/result-cache, (*5)


## Usage ### Cache * Create a class that extends ResultCache ``` php use Tequilarapido\ResultCache\ResultCache; class BooksCache extends ResultCache { public function key() { return 'app.books.all'; } public function data() { // Some heavy / resources consuming operations // ... return $books; } }
  • Now you can simply call the get method to fetch cache. If the cache is invalid or not yet created, the operations will be executed.

``` php class SomeController { public function books() { return (new BooksCache)->get(); } }, (*6)


* Clean the cache The package uses the default cache driver defined in your laravel application. You can clean the cache using the `artisan cache:clear` You can also clean the cache programmatically using : ``` php (new BooksCache)->forget()

Application locale aware cache

Sometimes we need to cache something, but we need multiple versions depending on the application locale. For this kind of use case we need to extend the LocaleAwareResultCache, and define the locales that are available in our application., (*7)

  • Create a class that extends LocaleAwareResultCache

``` php
use Tequilarapido\ResultCache\LocaleAwareResultCache;, (*8)

class BooksCache extends LocaleAwareResultCache {, (*9)

public function key() {
    return 'app.books.all';
}

public function data() {
    // Some heavy / resources consuming operations
    // We have access to $this->locale here to customize results according to locale
    // ...
    return $books;
}

public function  supportedLocales() {
    return ['en', 'fr', 'ar']
}

}, (*10)


* Now you can simply call the get method to fetch cache. If the cache is invalid or not yet created, the operations will be executed. ``` php class SomeController { public function books() { return (new BooksCache)->setLocale($locale)->get(); } }
  • Clean the cache

The package uses the default cache driver defined in your laravel application., (*11)

You can clean the cache using the artisan cache:clear, (*12)

You can also clean the cache programmatically using :, (*13)

``` php (new BooksCache)->forget(), (*14)


this will clean cache for all locales. ### Cache expiration By default, cache is created for one day. You can override the protected `$minutes` property on your cache class to specify how much minutes you want your cache before it gets invalidated. ``` php use Tequilarapido\ResultCache\ResultCache; class BooksCache extends ResultCache { protected $minutes = 60; // One hour // ... }

Changelog

Please see CHANGELOG for more information what has changed recently., (*15)

Testing

bash $ composer test, (*16)

Security

If you discover any security related issues, please email :author_email instead of using the issue tracker., (*17)

Contributing

Please see CONTRIBUTING for details., (*18)

Credits

License

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

The Versions

25/01 2017

dev-master

9999999-dev https://github.com/tequilarapido/result-cache

A simple and decoupled way to store resource consuming operations results in cache.

  Sources   Download

MIT

The Requires

 

The Development Requires

12/10 2016

0.0.2

0.0.2.0 https://github.com/tequilarapido/result-cache

A simple and decoupled way to store resource consuming operations results in cache.

  Sources   Download

MIT

The Requires

 

The Development Requires

12/10 2016

0.0.1

0.0.1.0 https://github.com/tequilarapido/result-cache

A simple and decoupled way to store resource consuming operations results in cache.

  Sources   Download

MIT

The Requires

 

The Development Requires