2017 © Pedro Peláez
 

package laravel-cacheable

Cacheable trait for Laravel models

image

bluesik/laravel-cacheable

Cacheable trait for Laravel models

  • Wednesday, June 27, 2018
  • by Blues
  • Repository
  • 1 Watchers
  • 1 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Laravel Cacheable trait

Description

This trait allows you to easily cache your model's data through a variety of handful methods., (*1)

NOTE:, (*2)

  • Cache is automatically cleared when a given model is saved/deleted

Installation

composer require bluesik/laravel-cacheable

Usage

Add at the top of your model file:, (*3)

<?php

use Bluesik\LaravelCacheable\Cacheable;

Then within a class:, (*4)

use Cacheable;

Available properties

protected $cacheExpiry;
  • Integer $cacheExpiry
    • A number of minutes till the cache expires.
    • Defaults to 24 hours
protected static $fullModelCaching
  • Boolean $fullModelCaching
    • Indicates whether models should be cached directly or converted to an array
    • Defaults to true
protected static $bustCacheOnSaved
  • Boolean $bustCacheOnSaved
    • Should cache be busted upon saving a model
    • Defaults to true
protected static $bustCacheOnDeleted
  • Boolean $bustCacheOnDeleted
    • Should cache be busted upon deleting a model
    • Defaults to true

Available methods

Get latest records

Model::getLatest($limit, $with, $orderBy);
  • Integer $limit, (*5)

    • How many records to getAll
    • Defaults to: 3
  • String $orderBy, (*6)

    • $orderBy - What column to use when sorting the data
    • Defaults to: created_at
  • Array $with, (*7)

    • $with - List of relationships to eager load
    • Defaults to: An empty array

Returns a Collection or an array, (*8)


Get a single record by its id

Model::getById($id);
  • Integer $id
    • Id of a record you want to get

Returns a Model, an array or null, (*9)


Get records where

Model::getWhere($column, $value, $with);
  • String $column
    • Column name
    • Defaults to: id
  • Mixed $value
    • Value to look for
    • Defaults to: an empty string
  • Array $with
    • An array of relationships to eager load
    • Defaults to: an empty array

Returns a Collection or an array, (*10)


Get all records

Model::getAll($with);
  • Array $with
    • An array of relationships to eager load
    • Defaults to: an empty array

Returns a Collection or an array, (*11)


Clear cache for a given model

Model::clearCache(); 

Enable full model caching

Model::enableFullModelCaching(); 

Disable full model caching (use arrays instead)

Model::disableFullModelCaching(); 

License

MIT, (*12)

The Versions

27/06 2018

dev-master

9999999-dev

Cacheable trait for Laravel models

  Sources   Download

MIT

by Bluesik

laravel cache eloquent trait model cacheable