All Projects → jameslkingsley → laravel-scoped-cache

jameslkingsley / laravel-scoped-cache

Licence: other
Easily cache items specific to your Eloquent models without having to append the ID.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-scoped-cache

eloquence
Eloquence provides a cache on top of Eloquent that prevents multiple models being created for a single database row using the Identity Map design pattern.
Stars: ✭ 18 (-35.71%)
Mutual labels:  eloquent
plug
A collection of pluggable traits for Eloquent (Laravel) models
Stars: ✭ 13 (-53.57%)
Mutual labels:  eloquent
state-machine
The hyn state machine package is a flexible library that helps you move Eloquent models from States through Transitions while emitting events along the way.
Stars: ✭ 14 (-50%)
Mutual labels:  eloquent
laravel-attribute-observer
Observe (and react to) attribute changes made on Eloquent models.
Stars: ✭ 59 (+110.71%)
Mutual labels:  eloquent
eloquent-filemaker
A Model extension and Eloquent driver for Laravel connecting to FileMaker through the Data API
Stars: ✭ 38 (+35.71%)
Mutual labels:  eloquent
encryptable
Laravel package for persisting encrypted Model properties, providing decryption when accessed.
Stars: ✭ 26 (-7.14%)
Mutual labels:  eloquent
Laravel Database Encryption
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Stars: ✭ 238 (+750%)
Mutual labels:  eloquent
laravel-sybase
Connection and Laravel Eloquent driver for Sybase
Stars: ✭ 29 (+3.57%)
Mutual labels:  eloquent
laravel-simplegrid
A simple component for generating powerful grids with Laravel.
Stars: ✭ 35 (+25%)
Mutual labels:  eloquent
acorn-db
Provides Acorn projects with Eloquent Models for WordPress data.
Stars: ✭ 30 (+7.14%)
Mutual labels:  eloquent
laratools
A collection of useful everyday tools for Laravel
Stars: ✭ 17 (-39.29%)
Mutual labels:  eloquent
inertiajs-tables-laravel-query-builder
Inertia.js Tables for Laravel Query Builder
Stars: ✭ 391 (+1296.43%)
Mutual labels:  eloquent
laravel-query-inspector
The missing laravel helper that allows you to inspect your eloquent queries with it's bind parameters
Stars: ✭ 59 (+110.71%)
Mutual labels:  eloquent
laravel-nestedupdater
Package for allowing updating of nested Eloquent model relations using a single nested data array.
Stars: ✭ 19 (-32.14%)
Mutual labels:  eloquent
laravel-cachable-attributes
Allows to cache attribute accessor values in an easy way.
Stars: ✭ 24 (-14.29%)
Mutual labels:  eloquent
Bouncer
Eloquent roles and abilities.
Stars: ✭ 2,763 (+9767.86%)
Mutual labels:  eloquent
slim-boilerplate
A PHP boilerplate,for a fast API prototyping based on Slim Framework, for start projects with Eloquent ORM, Validation, Auth (JWT), Repositories and Transformers ready
Stars: ✭ 58 (+107.14%)
Mutual labels:  eloquent
eloquent-hashids
Automatically generate and persist Hashids for newly created Eloquent models.
Stars: ✭ 17 (-39.29%)
Mutual labels:  eloquent
php-orm-benchmark
The benchmark to compare performance of PHP ORM solutions.
Stars: ✭ 82 (+192.86%)
Mutual labels:  eloquent
eloquent-filter
Library to form search criteria through expressions in the query string
Stars: ✭ 23 (-17.86%)
Mutual labels:  eloquent

Model specific cache items made easy

This package adds a trait that provides a cache method for interacting with your app's cache, but scoped to your Eloquent models. This removes the need to constantly append the model ID to your cache keys. Just access your cache like this instead $user->cache('Avatar').

Under the hood it will prefix your cache keys with a generated model-specific key, in the format Model_ID:your-key. You can completely override this format by implementing the getScopedCacheKey method on your model.

Installation

You can install the package via composer:

composer require jameslkingsley/laravel-scoped-cache

Usage

Import the trait and use it on any Eloquent model. You can also use it on non-eloquent classes, providing they have a getKey method that returns their unique reference.

use Kingsley\ScopedCache\ScopedCache;

class User extends Model
{
    use ScopedCache;
}

Now you can use the cache how you would normally. You can set/get items directly from the cache method, or call any other cache method by leaving the argument list empty.

$user->cache(['name' => $user->name], 5);
$user->cache('name', 'default name');

$user->cache()->remember('name', 5, function () {
    // $this refers to the model this cache instance is scoped to
    return $this->name;
});

Keep in mind that this package is expecting the first argument of proxied calls to the cache to be the cache key. There might be some cases where custom macro's break this format.

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].