oanhnn/cache

此包已被废弃,不再维护。作者建议使用 cache 包。
此包的最新版本(1.1)没有可用的许可信息。

Cache 是一个 CakePHP 插件,允许您轻松缓存查找结果

安装: 642

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:cakephp-plugin

1.1 2014-08-21 03:20 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:29:13 UTC


README

Cache 是一个 CakePHP 插件,允许您轻松缓存查找结果。虽然大多数查询缓存解决方案都要求您在 AppModel 中覆盖 Model::find(),但 Cache 只需要为您的模型添加一个行为。

是否有很少改变的设置?是否有数据库状态列表或某些永不改变但您仍希望在数据库中保留的内容?就像缓存您的结果一样?使用 Cache!

需求

  • CakePHP >= 2.0.x(检查标签以获取 CakePHP 的旧版本)

安装

用法

    var $actsAs = array(
        'Cache.Cached'
    );

默认情况下,Cache 使用 core.php 文件中的 'default' 缓存配置。如果您想使用不同的配置,只需在 'config' 键中传递即可。

    /**
     * @var array Using Behavior
     */
    public $actsAs = array(
        'Cache.Cached' => array(
            'config' => '_cake_queries_',
            'map' => '_cake_queries_map_',
            'clearOnDelete' => true,
            'clearOnSave' => true,
            'auto' => true,
            'gzip' => false,
        ),
    );

最好将 Cache 放在行为列表的最后,以便查询 Cacher 反映先前行为可能做出的更改。

可以传递的选项

  • config 要复制的现有 Cache 配置的名称(默认 'default')
  • map 要复制的现有 Cache 配置的名称(默认 'default'),用于 '缓存键映射'
  • clearOnSave 是否在保存时删除缓存(默认 true
  • clearOnDelete 是否在删除时删除缓存(默认 true
  • auto 自动缓存(默认 false
  • gzip 自动压缩/解压缩缓存数据(默认 false

Model::find()Controller::paginate() 等一起使用 Cache

如果将 auto 设置为 false,您可以在查询中传递一个 'cache' 键,该键可以是 true 以缓存结果,false 以不缓存它,或数组选项以覆盖该特定调用的默认设置。

    // cache the results of this query for a day
    $this->Post->find('all', array(
		  'conditions' => array('Post.name LIKE' => '%awesome%'),
		  'cache' => array(
                'config'   => '_cake_queries_',
                'gzip'     => false,
                'key'      => 'key_of_cache',
                'duration' => '+1 days'
       ),
    ));
    // don't cache the results of this query at all
    $this->Post->find('all', array(
		  'conditions' => array('Post.name LIKE' => '%lame%'),
		  'cache' => false
    ));
    // cache using the default settings even if auto = false
    $this->Post->find('all', array(
		  'conditions' => array('Post.name LIKE' => '%okay i guess%'),
		  'cache' => true
    ));

它的工作原理

Cache 会在任何查找查询中拦截并临时更改数据源,以处理检查缓存。

您始终可以使用 Behavior::detach()Behavior::disable() 禁用 Cache。

特性

  • 只需将行为附加到模型即可快速轻松地缓存
  • 使用 $this->Post->clearCache() 在线清除特定模型的缓存
  • 通过传递条件到 clearCache() 清除特定查询

任务列表

  • 编写测试脚本
  • 编写安装说明

感谢