承接 becklyn/cache 相关项目开发

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

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

becklyn/cache

Composer 安装命令:

composer require becklyn/cache

包简介

A cache bundle providing a simple (and fast) cache

README 文档

README

Provides a simple cache, that should be easy to use and high performance. Warning: for highly concurrent usage you should either prepare the cache in advance or use symfony's own cache, as it has proper cache stampede protection.

Usage

Fetch the simple cache factory and get the cache item:

use Becklyn\Cache\Cache\SimpleCacheFactory;

class MyService
{
    private SimpleCacheItemInterface $cache;

    /**
     */
    public function __construct (SimpleCacheFactory $cacheFactory)
    {
        $this->cache = $cacheFactory->getItem(
            "my.cache.key",
            fn () => $this->loadItems()
        );
    }


    /**
     * Returns the cached or fresh items, depending on several conditions. 
     */
    public function getItems () : array
    {
        return $this->cache->get();
    }
    

    /**
     * Loads the items from the database
     */
    public function loadItems () : array
    {
        // ...
    }
}

Caching Based on Symfony Config

You can either pass the cache key and generator to the getItem() method (like in the example above), or you can additionally pass in resources that should be tracked and can be used for cache invalidation.

If you pass resources, this will be a two-level cache:

  1. first level will be the plain symfony/cache, which is really fast but has no proper way of cache invalidation.
  2. second level will be the ConfigCache which will automatically be invalidated if some of the tracked resources change.
$cacheFactory->getItem(
    "my.cache.key",
    fn () => $this->loadItems(),
    // eg. if your cache status depends on routing resources
    $this->router->getRouteCollection()->getResources()
 );

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2020-04-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固