承接 sfneal/caching 相关项目开发

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

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

sfneal/caching

最新稳定版本:4.1.0

Composer 安装命令:

composer require sfneal/caching

包简介

Traits & interfaces for utilizing cache mechanisms to store frequently retrieved data.

README 文档

README

Packagist PHP support Latest Version on Packagist Build Status StyleCI Scrutinizer Code Quality Total Downloads

Traits & interfaces for utilizing cache mechanisms to store frequently retrieved data in Laravel applications.

Installation

You can install the package via composer:

composer require sfneal/caching

Usage

1. Add caching to an eloquent query

During the first call to (new CountUnreadInquiriesQuery())->fetch(600) in a fresh application instance (or for the first time since flushing the cache) the output of the execute method will be stored in the Redis cache for 5 minutes (600 seconds).

If another call to (new CountUnreadInquiriesQuery())->fetch(600) is made within the next 5 minutes, the previous output will be retrieved from the Redis cache, forgoing the need to execute a full query to the database. In this example the time saved is minimal but time saving become increasingly significant as the complexity of a query increases.

# Importing an example model that extends Sfneal/Models/AbstractModels
use App\Models\Inquiry;

# Import Cacheable trait that stores the output of the execute method in a Redis cache using the cacheKey method to set
# the key.  Any serializable output from execute can be stored, in this case we're simply storing an integer
use Sfneal\Caching\Traits\Cacheable;

# Importing AbstractQuery as we're building an Eloquent query cache
use Sfneal\Queries\AbstractQuery;

class CountUnreadInquiriesQuery extends AbstractQuery
{
    use Cacheable;

    /**
     * Retrieve the number of unread Inquiries.
     *
     * @return int
     */
    public function execute(): int
    {
        return Inquiry::query()->whereUnread()->count();
    }

    /**
     * Retrieve the Queries cache key.
     *
     * @return string
     */
    public function cacheKey(): string
    {
        # using AbstractModel::getTableName() to dynamically retrievethetable name to set the cache prefix
        return Inquiry::getTableName().':unread:count';
    }
}

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email stephen.neal14@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

PHP Package Boilerplate

This package was generated using the PHP Package Boilerplate.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-18