duanchu0031 2015-02-03 16:21 采纳率: 0%
浏览 29
已采纳

自定义缓存引擎在CakePhp 2.6中不起作用

I'm trying to implement Zend Cache from ZF2 inside CakePhp to make use of it's tagging features, among others.

I created a class inside /app/Lib/Cache/Engine/ZendCacheEngine.php

class ZendCacheEngine extends CacheEngine {
   //All abstract functions from Cake's CacheEngine are 

    public function init($settings = array()){
        //Code here....
    }

    //Along with read, write, delete, etc...
}

For the time being, i only have a print "function name" inside these functions and a return. I did this in my efforts to debug what is going on.

Inside my bootstrap.php I set the config for my custom class:

Cache::config('custom_zend', array(
    'engine' => 'ZendCache',
    'duration' => '+1 hours',
    'probability' => 100,
));

When I try to use it inside my Controllers, the cache read and write functions are being ignored completely. (Function name not being printed in my case, except for the init function)

public function news($id, $something) {
        $result = Cache::read('news', 'custom_zend');
        if (!$result) {

            $result = $this->News->find('all'); // For the sake of simplicity here
            Cache::write('news', $result, 'custom_zend');
        }
        $this->set('news',$news);   
    }

Bottom line, I am assuming the file is in the correct place and the configuration is correct (since the init() function inside my custom class is being called).

I need to know why the actual read/write/etc... are not being called.

  • 写回答

1条回答 默认 最新

  • duanlan7239 2015-02-04 10:02
    关注

    It turns out the init() was not setting the $settings array properly, that's why the other functions were not being called.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化