All Projects → SimpleSoftwareIO → Simple Cache

SimpleSoftwareIO / Simple Cache

Licence: mit
An easy to use Caching trait for Laravel's Eloquent Models.

Projects that are alternatives of or similar to Simple Cache

Lada Cache
A Redis based, fully automated and scalable database cache layer for Laravel
Stars: ✭ 424 (+2131.58%)
Mutual labels:  eloquent, cache, laravel
Eloquent Ldap
A Laravel 5.1 package that first tries to log the user against the internal database if that fails, it tries against the configured LDAP/AD server.
Stars: ✭ 19 (+0%)
Mutual labels:  eloquent, laravel, laravel-package
Laravel Repositories
[ABANDONED] Rinvex Repository is a simple, intuitive, and smart implementation of Active Repository with extremely flexible & granular caching system for Laravel, used to abstract the data layer, making applications more flexible to maintain.
Stars: ✭ 664 (+3394.74%)
Mutual labels:  eloquent, cache, laravel
Eloquent Approval
Approval process for Laravel Eloquent models
Stars: ✭ 79 (+315.79%)
Mutual labels:  eloquent, laravel, laravel-package
Laravel Deletable
👾 Gracefully restrict deletion of Laravel Eloquent models
Stars: ✭ 137 (+621.05%)
Mutual labels:  eloquent, laravel, laravel-package
Laravel Cacheable
Rinvex Cacheable is a granular, intuitive, and fluent caching system for eloquent models. Simple, but yet powerful, plug-n-play with no hassle.
Stars: ✭ 107 (+463.16%)
Mutual labels:  eloquent, cache, laravel
Laravel Schedulable
Schedule and unschedule eloquent models elegantly without cron jobs
Stars: ✭ 78 (+310.53%)
Mutual labels:  eloquent, laravel, laravel-package
Blogetc
Easily add a full Laravel blog (with built in admin panel and public views) to your laravel project with this simple package.
Stars: ✭ 198 (+942.11%)
Mutual labels:  eloquent, laravel, laravel-package
Laravel Eloquent Query Cache
Adding cache on your Laravel Eloquent queries' results is now a breeze.
Stars: ✭ 529 (+2684.21%)
Mutual labels:  eloquent, cache, laravel
Laravel Friendships
This package gives Eloquent models the ability to manage their friendships.
Stars: ✭ 651 (+3326.32%)
Mutual labels:  eloquent, laravel
Laravel Open Source Projects
A Web Artisan list of categorized OPEN SOURCE PROJECTS built with Laravel PHP Framework.
Stars: ✭ 676 (+3457.89%)
Mutual labels:  laravel, laravel-package
Laravel Log
Simple API to write logs for Laravel.
Stars: ✭ 19 (+0%)
Mutual labels:  laravel, laravel-package
Laravel Imageup
Auto Image & file upload, resize and crop for Laravel eloquent model using Intervention image
Stars: ✭ 646 (+3300%)
Mutual labels:  eloquent, laravel
Laravel Heyman
Declarative style of authorization and validation in laravel.
Stars: ✭ 677 (+3463.16%)
Mutual labels:  laravel, laravel-package
Laravel Mongodb
A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)
Stars: ✭ 5,860 (+30742.11%)
Mutual labels:  eloquent, laravel
Chat
A Laravel chat package. You can use this package to create a chat/messaging Laravel application.
Stars: ✭ 710 (+3636.84%)
Mutual labels:  laravel, laravel-package
Orm
A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen
Stars: ✭ 712 (+3647.37%)
Mutual labels:  laravel, laravel-package
Laravel Shopify
A full-featured Laravel package for aiding in Shopify App development
Stars: ✭ 634 (+3236.84%)
Mutual labels:  laravel, laravel-package
Sweet Alert
A BEAUTIFUL, RESPONSIVE, CUSTOMIZABLE, ACCESSIBLE (WAI-ARIA) REPLACEMENT FOR JAVASCRIPT'S POPUP BOXES FOR LARAVEL
Stars: ✭ 696 (+3563.16%)
Mutual labels:  laravel, laravel-package
Laravel
Laravel Model Generator
Stars: ✭ 715 (+3663.16%)
Mutual labels:  eloquent, laravel

Simple Cache

Build Status Latest Stable Version Latest Unstable Version License Total Downloads

Try our dead simple, free file transfer service keep.sh

Configuration

Composer

First, add the Simple Cache package to your require in your composer.json file:

"require": {
	"simplesoftwareio/simple-cache": "~1"
}

Next, run the composer update command.

Usage

The cacheable trait may be used by adding the trait to the Eloquent model of your choice.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use SimpleSoftwareIO\Cache\Cacheable;

class User extends Model
{
    use Cacheable;
}

Yes, it really is that simple to use. The settings will use the default Cache store set up in your Laravel application. Further, models will be cached for 30 minutes by default.

Properties

cacheLength

You may adjust the default cache length by modifying the cacheLength property on the model.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use SimpleSoftwareIO\Cache\Cacheable;

class User extends Model
{
    use Cacheable;
    protected $cacheLength = 60; //Will cache for 60 minutes
}

cacheStore

The configured cache store may also be adjusted by modifying the cacheStore property. The cache store will need to be set up in your application's config/cache.php configuration file.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use SimpleSoftwareIO\Cache\Cacheable;

class User extends Model
{
    use Cacheable;
    protected $cacheStore = 'redis'; //Will use the configured `redis` store set up in your `config/cache.php` file.
}

cacheBusting

Cache busting will automatically invalid the cache when an insert/update/delete command is ran by your models. You can enable this feature by setting the cacheBusting property to true on your Eloquent model. By default this feature is disabled.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use SimpleSoftwareIO\Cache\Cacheable;

class User extends Model
{
    use Cacheable;
    protected $cacheBusting = true;

}

Be careful! Eloquent Model's with a high amount of insert/update/delete traffic should not use the cache busting feature. The large amount of changes will invalid the model too often and cause the cache to be useless. It is better to set a lower cache length to invalid the results frequently if up to date data is required.

Methods

flush()

The flush method will flush the cache for a model.

(new User)->flush()  //Cache is flushed for the `User` model.

isBusting()

isBusting will return the current status of the cacheBusting property.

if((new User)->isBusting()) {
    // Is cache busting
}

remember($length)

remember will set the length of time in minutes to remember an Eloquent query.

User::remember(45)->where('id', 4')->get();

rememberForever()

rememberForever will remember a query forever. Well, technically 10 years but lets pretend it is forever eh?

User::rememberForever()->where('id', 4')->get();

dontRemember()

And lastly, dontRemember will not cache a query result.

User::dontRemember(0)->where('id', 4')->get();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].