承接 sitegeist/stalemate 相关项目开发

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

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

sitegeist/stalemate

Composer 安装命令:

composer require sitegeist/stalemate

包简介

Cache with stale period and asynchronous updates

README 文档

README

Varnish like cache for Neos.Flow with asynchronous updates that returns stale results in the meantime

This package implements cache that will return stale values for a configurable time while the cache values are updated asynchronously. Such behavior is well known from the varnish cache but not common in php.

The core concept is that the staleMateCache gets an identifier and closure for generating the required information if it cannot be found in the cache. The closure is called immediately if no cached result is found. If a result is found the cached result is returned.

In case the cached item is older than the intended lifetime the stale item is still returned immediately but the closure is scheduled for evaluating during the shutdown of the flow application and thus after the response has been sent to the user.

Authors & Sponsors

The development and the public-releases of this package is generously sponsored by our employer https://www.sitegeist.de.

Usage

The StaleMate cache is injected from flow.

    use \Sitegeist\StaleMate\Cache\ClosureCache as StaleMateCache;     
    
    /**
     * @var VariableFrontend
     */
    protected $cache;
    
    /**
     * @var StaleMateCache
     */
    protected $staleMateCache;

    /**
     * @param VariableFrontend $cache
     * @return void
     */
    public function injectCache(VariableFrontend $cache): void
    {
        $this->cache = $cache;
    }
    
    public function initializeObject()
    {
        $staleMateCache = new \Sitegeist\StaleMate\Cache\ClosureCache(
            $this->cache, // the variable frontend to cache the data in
            8600, // lifetime for the items
            4300, // gracePeriod where items are updated asynchronous
            60 // lockPeriod for asynchronous updates 
        );
    }

The cache is then called via the resolve method with an identifier and aclosure. Please note that the closure cannot have arguments but instead may use variables from the context the method is called from.

    $result = $this->staleMateCache->resolve(
        $cacheId, // identifier used to store the result, has to be unique
        function () use ($stuffThatIsNeeded) {
            $response = ... some expensive operation ...
            return $response;
        }, // closure to generate the result if no result is in the cache
        ['someTag'], // tags for the cache item  
        86400, // lifetime of the cached result until a refresh is needed
        43200, // gracePeriod after lifetime where an update is performed async and the stale result is used
        60 // lockPeriod for asynchronous updates 
    );

Installation

Sitegeist.StaleMate is available via packagist. Just run composer require sitegeist/stalemate to install it. We use semantic-versioning so every breaking change will increase the major-version number.

Comparison to Symfony Cache Contracts

The approach implemented here is somewhat similar to the symfony cache contracts but deviates in a specific way. Symfony Cache Contracts will roll a dice to upgrade cache entries before they expire to prevent mass invalidation and recomputation. Stalemate on the other hand will return the cached item and recompute the value after the response was sent to the user.

Contribution

We will gladly accept contributions. Please send us pull requests.

sitegeist/stalemate 适用场景与选型建议

sitegeist/stalemate 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18.85k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 10 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 sitegeist/stalemate 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sitegeist/stalemate 我们能提供哪些服务?
定制开发 / 二次开发

基于 sitegeist/stalemate 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2022-10-14