承接 mrdilbaz/model-cache 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mrdilbaz/model-cache

Composer 安装命令:

composer require mrdilbaz/model-cache

包简介

Easily cache your Laravel's Eloquent models

README 文档

README

Easily cache your Laravel's Eloquent models.

Build Status Coverage Status Latest Stable Version Total Downloads

Requirements

  • Added support for php 8 and laravel 10

  • PHP >= 8.0

  • Laravel 6 / 7 / 8 / 9 / 10

Installation

Install via composer :

composer require authentik/eloquent-cache

How it works

  • When Eloquent fetches models, the JSON representations of the model instances are cached.

  • Subsequently, when eloquent fetches a model by ID, the cached JSON will be converted back into an instance.

Usage

Use the Cacheable trait in the models you want to cache.

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Authentik\EloquentCache\Cacheable;

class Category extends Model
{
    use Cacheable;


    /*
     * You can optionally override the following functions:
     */
    
    // Time To Live in minutes (default value: 0 => no TTL)
    public function getCacheTTL() {
        return 60;
    }

    // default value: the lowercase name of the model
    public function getCacheTagName() {
        return 'cat';
    }

    // Cache busting will automatically invalidate the cache when model instances are updated or deleted.
    // default value: true
    public function isCacheBustingEnabled() {
        return false;
    }

    // Whether or not to keep model instances in a static array cache
    //  (useful to avoid querying the cache store/building instances from json multiple times)
    // default value: true
    public function isStaticCacheEnabled() {
        return false;
    }
}

To manually cache a model instance, use the cache method.

Category::find(1)->cache();

To invalidate the cache for a model instance, use the refresh or flush method.

$refreshedInstance = Category::find(1)->refresh();

// or

Category::flush(Category::find(1));

To invalidate the cache for all instances of a model, use the flush method.

Category::flush();

Changelog

Click Here

统计信息

  • 总下载量: 44
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-only
  • 更新时间: 2024-02-12