定制 contenir/cache 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

contenir/cache

最新稳定版本:v0.1.1

Composer 安装命令:

composer require contenir/cache

包简介

Framework-agnostic page-cache control for Contenir CMS — admin writes a purge signal, Sites read it and flush.

README 文档

README

Framework-agnostic page-cache control for Contenir CMS.

The CMS lets an operator toggle page caching on or off, decide which request signals participate in cache-key generation (query/post/session/files/cookie), and exclude specific URL patterns. The consuming Site (Mezzio, Laminas MVC, anything else) reads those settings on every request and applies them in its caching layer.

This package provides the domain — an immutable state value plus a repository interface, with file-based and in-memory implementations. Framework-specific listeners come from sibling packages (e.g. contenir/cache-laminas-mvc).

Install

composer require contenir/cache

Add contenir/config if you intend to use Repository\FileRepository (admin-side writer). Sites that read state from the merged Laminas/Mezzio config — and use Repository\InMemoryRepository in tests — don't need it.

Usage

Reading state

use Contenir\Cache\Repository\FileRepository;

$repo = new FileRepository('/var/www/shared/pagecache.local.php');
$state = $repo->get();

if ($state->enabled) {
    // Apply cache options ($state->options) and route overrides ($state->routes)
}

Writing state (admin)

use Contenir\Cache\CacheControl;

$repo->save(new CacheControl(
    enabled: true,
    options: ['cache_with_query' => true, 'cache_with_session' => false],
    routes:  ['/api.*' => ['cache' => false]],
));

File format

FileRepository reads and writes a PHP file under the pagecache namespace, so the same file can be merged directly into a Laminas/Mezzio site config:

<?php

return [
    'pagecache' => [
        'options' => [
            'cache'              => true,
            'cache_with_query'   => true,
            'cache_with_session' => false,
        ],
        'routes' => [
            '/api.*' => ['cache' => false],
        ],
    ],
];

A missing or unreadable file resolves to disabled state with empty options and routes, so first-run consumers never serve cached content before the admin has explicitly opted in. Other top-level config keys (errors, maintenance, …) and operator-authored sibling options are preserved on save.

Testing

InMemoryRepository is shipped in src/ so consumers can use it in their own test suites:

use Contenir\Cache\Repository\InMemoryRepository;
use Contenir\Cache\CacheControl;

$repo = new InMemoryRepository(CacheControl::enabled());

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固