douhuan3420 2014-02-17 21:22
浏览 45
已采纳

如何在CakePHP中完全禁用Cache并且不向/ app / tmp写入任何内容?

I have working CakePHP 2.5.dev app and I have disabled cache in CakePHP via

Configure::write('debug', 2);
Configure::write("Cache.disable", true);

in app/Config/core.php

Unfortunately I must deploy this app to a server where I can't write into app/tmp directory.

I checked answers on StackOverflow how to disable cache and above lines into app/Config/core.php and even commented-out rest lines which are responsible for caching ie

/**
 * Configure the cache used for general framework caching. Path information,
 * object listings, and translation cache files are stored with this configuration.
 */
//Cache::config('_cake_core_', array(
//  'engine' => $engine,
//  'prefix' => $prefix . 'cake_core_',
//  'path' => CACHE . 'persistent' . DS,
//  'serialize' => ($engine === 'File'),
//  'duration' => $duration
//));

/**
 * Configure the cache for model and datasource caches. This cache configuration
 * is used to store schema descriptions, and table listings in connections.
 */
//Cache::config('_cake_model_', array(
//  'engine' => $engine,
//  'prefix' => $prefix . 'cake_model_',
//  'path' => CACHE . 'models' . DS,
//  'serialize' => ($engine === 'File'),
//  'duration' => $duration
//));

But when I run my app on production server, I get an exception.

Warning: /home/kowalski_m/public_html/projekt2/app/tmp/cache/persistent/ is not writable in /home/kowalski_m/public_html/projekt2/lib/Cake/Cache/Engine/FileEngine.php on line 384

Fatal error: Uncaught exception 'CacheException' with message 'Cache engine _cake_core_ is not properly configured.' in /home/kowalski_m/public_html/projekt2/lib/Cake/Cache/Cache.php:181 Stack trace: #0 /home/kowalski_m/public_html/projekt2/lib/Cake/Cache/Cache.php(151): Cache::_buildEngine('_cake_core_') #1 /home/kowalski_m/public_html/projekt2/app/Config/core.php(376): Cache::config('_cake_core_', Array) #2 /home/kowalski_m/public_html/projekt2/lib/Cake/Core/Configure.php(72): include('/home/kowalski_...') #3 /home/kowalski_m/public_html/projekt2/lib/Cake/bootstrap.php(175): Configure::bootstrap(true) #4 /home/kowalski_m/public_html/projekt2/app/webroot/index.php(94): include('/home/kowalski_...') #5 /home/kowalski_m/public_html/projekt2/index.php(41): require('/home/kowalski_...') #6 {main} thrown in /home/kowalski_m/public_html/projekt2/lib/Cake/Cache/Cache.php on line 181

enter image description here

So it looks like caching is still working.

I can't get write laws for this directory in this server. I don't have access to root.

How can I disable totally caching and setup CakePHP to don't write anything into /app/tmp ?

  • 写回答

1条回答 默认 最新

  • dpa55065 2014-02-18 04:41
    关注

    Do you have APC installed on your server?

    If so, then you can use this to cache the core. This is faster than hitting the filesystem anyway.

    You WILL need those lines configuring the cake_core, just be sure to set

    $engine = 'Apc';
    

    above the cache configuration lines.

    If using APC on a shared server, it's important to set your prefix properly, I use the following config which works on shared hosting with multiple cake apps installed:

    Cache::config(
        '_cake_core_',
        array(
            'engine' => $engine,
            'prefix' => $prefix . 'cake_core_' . Inflector::slug(ROOT),
            'path' => CACHE . 'persistent' . DS,
            'serialize' => ($engine === 'File'),
            'duration' => $duration
        )
    );
    

    Alternatively:

    You don't need root access to set permissions for that folder, all you need is FTP access. You can set the permissions for app/tmp/* to 777 using FTP, which is what I do for some other temporary folders that I use.

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

报告相同问题?

悬赏问题

  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败