Rememberable

Codacy Badge StyleCI License Total Downloads Latest Stable Version

Model caching for Laravel

This package can work independently of the Enso ecosystem.

For live examples and demos, you may visit laravel-enso.com

Installation

Comes pre-installed in Enso.

To install outside of Enso: composer require laravel-enso/rememberable

Features

  • comes with a trait that provides helper methods for quick and easy caching usage (setting and retrieving)
  • the cache lifetime may be set per model or the per-project
  • uses the Laravel cache() helper method so it is transparent to the cache mechanism/implementation

Usage

  1. Use the Rememberable trait in the CachedModel that you want to track

  2. You MUST set the caching duration (in minutes) by either:

    • adding a protected $cacheLifetime = 123; property in your CachedModel
    • setting the enso.config.cacheLifetime configuration value as desired
  3. Whenever you need to retrieve a cached model instead of getting it directly from the database:

    CachedModel::find($id)
    

    you should get it from cache:

    CachedModel::cacheGet($id)
    

You may use the global enso.config.cacheLifetime configuration together with local/per-model cache lifetime values.

If given, the trait favors the per-model cache lifetime value over the global configuration value, thus you can override the global setting as required.

Contributions

are welcome. Pull requests are great, but issues are good too.

License

This package is released under the MIT license.