Creating sub-folders in Caching, Cakephp - cakephp

I have a Cache folder in tmp.
I want a sub-folder in the cache folder, to store cache files of a particular page ONLY in that folder.
What should I do?

Find bootstrap.php in your app/config
Replace the following lines
Cache::config('users_cache', array( // users_cache is the custom cache log name
'engine' => File,
'prefix' => 'cake_',
'path' => CACHE . 'users' . DS, // added sub-directory in users in tmp/cache
'serialize' => true,
'duration' => '+360 minutes'
));
Now, create a directory in your app/tmp/cache/users
Then use it as the following format
Cache::write('enter_name', $users,'users_cache');
For best reference read the following article Cache::write

Related

CakePHP Memcached CakePHP2.5.x

I have upgraded to CakePHP 2.5.x series and now trying to implement the new Memcached engine that replaces Memcache; however I am getting the following:
_cake_core_ cache was unable to write 'cake_dev_en-us' to Memcached cache in ...
Uncaught exception 'CacheException' with message ' is not a valid serializer engine for Memcached'
I have updated bootstrap.php and core.php with the correct values. Memcached is working correctly on my Ubuntu 14.04 server using port 11211 on localhost (127.0.0.1). Any help would be appreciated
Thanks
This is because in the Config/core.php, the following 'serialize' parameter will be set as false if the cache engine is set as "Memcached", however, MemcachedEngine requires the 'serialize' to be set among 'php','igbinary' and 'json'. You may just comment out the "serialize" line, so 'php' will be the default value.
/**
* 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
));

CakePHP cache permissions issues

This week I have moved a CakePHP application on the server so that it is served from C:\path\current\ where current is a symlink to C:\path\versions[date]. Previously the app was in C:\inetpub\wwwroot.
Thus each time I deploy changes, I make a new version of the app and the deploy script updates the symlink. In order to avoid having to re-create the temp dir each time, I've moved the temp dir to C:\path\app_tmp\ - the deploy script drops a symlink at app\tmp pointing to this temp dir.
The server is Windows Server 2008 R2 and the web server is IIS7. C:\path\app_tmp\ has full permissions (Everyone has Full Control).
Since making the change to the location of the app and the tmp dir, users are reporting sporadic instances of warnings appearing at the top of the page. The app is in debug=0 but these do not appear in the error log.
Examples:
Warning:
unlink(C:\path\app_tmp\cache\models\prefix_cake_model_default_app_modelname):
Permission denied in
C:\path\versions[date]\www\lib\Cake\Cache\Engine\FileEngine.php on
line 254
Warning:
SplFileInfo::openFile(C:\path\versions[date]\www\app\tmp\cache\models\prefix_cake_model_default_app_modelname):
failed to open stream: Permission denied in
C:\path\versions[date]\www\lib\Cake\Cache\Engine\FileEngine.php on
line 313
(actual paths/model names obfuscated)
Here is what I have in core.php:
$engine = 'File';
$duration = '+999 days';
if (Configure::read('debug') >= 1) {
$duration = '+10 seconds';
}
if (!isset($_SERVER['HTTP_HOST'])) {
$prefix = 'cmd_';
}
else {
$prefix = $_SERVER['HTTP_HOST'] . '_';
}
Cache::config('_cake_core_', array(
'engine' => $engine,
'prefix' => $prefix . 'cake_core_',
'path' => CACHE . 'persistent' . DS,
'serialize' => ($engine === 'File'),
'duration' => $duration,
'mask' => 0666
));
Cache::config('_cake_model_', array(
'engine' => $engine,
'prefix' => $prefix . 'cake_model_',
'path' => CACHE . 'models' . DS,
'serialize' => ($engine === 'File'),
'duration' => $duration,
'mask' => 0666
));
I have this in bootstrap.php:
Cache::config('default', array('engine' => 'File'));
Any suggestions? I have a feeling that perhaps the permissions aren't being inherited properly from the app\tmp symlink to the actual tmp dir, but on the other hand the error logs seem to write correctly and these errors are only sporadic.
One idea i had was to switch to using Wincache but then I can't find any information on how I clear the model cache when I've got a database change to deploy (currently I can just clear the model cache with a grunt task).
I haven't been able to resolve this while sticking to using the default file caching. I've switched the application to using Wincache. To clear model cache when a database change is made, I've written a short script to execute:
Cache::clear('_cake_model_');
This has to be done in the browser because CLI uses a different cache from IIS, but I've made it "gruntable" by using grunt-shell and just executing: start http://script/location/clear_cache

CakePHP + NGINX + Memcache

I am trying to use Memcache on NGINX for CakePHP (2.4.7) but when I update the core.php & bootstrap.php to do this I am then thrown the following exception:
Fatal error: Uncaught exception 'CacheException' with message 'Cache engine _cake_core_ is not properly configured
I have tried to search if any other configuration is required but can't see anything. Any help would be appreciated
Thanks,
First of all you need be sure that your Memcached configured and working properly.
Check memcached port (11211 if default settings) / process etc... for example memcached -u www-data -vv.
Then if you using memcached default configurations you should change core.php configurations like following:
Uncomment section about memcached. After it it's should looks like this:
Cache::config('default', array(
'engine' => 'Memcache', //[required]
'duration' => 1800, //[optional]
'probability' => 100, //[optional]
'prefix' => Inflector::slug(APP_DIR) . '_',
'servers' => array(
'127.0.0.1:11211'),
'persistent' => true,
'compress' => false));
Now change $engine = 'File'; to $engine = 'Memcache';
Use caching for example in controller you need write data with key => value, then access that data with key. Example:
Cache::write($key, $value);
Cache::read($key);
That's all.
Hope it's help you.

Cakephp: issue with permissions when using the Apc cache

When using the file cache, this config let me write/read the cache from a shell script
Cache::config('default', array(
'engine' => 'File',
'mask' => 0666
));
However, when using something like this
Cache::config('default', array(
'engine' => 'Apc',
'mask' => 0666 // I don't think this is used by Apc cache.
));
I get permission errors when saving/reading the cache from a shell script. The Apc cache is working fine when running from regular page loads though. I understand that shell scripts aren't executed from the same user as regular page loads, but I don't know how to set the Apc cache permissions correctly.
Here's my shell script:
class HelloShell extends AppShell {
public function main(){
Cache::write('Hello', 5);
}
}
Here's the error
Warning Error: default cache was unable to write 'hello' to Apc cache in [/home/pi/MyProject/lib/Cake/Cache/Cache.php, line 325]
You need to enable APC for php-cli
http://www.php.net/manual/en/apc.configuration.php#ini.apc.enable-cli
because shell jobs runs as command line php
Well, you just answered your question. Have you tried changing the permissions of the App/tmp/ directory to 777?
#chmod -R 777 app/tmp

CakePhp Plugin: Problems with routing

Well, I am struggling for 2 hours trying to finding out how this not works.
The problem:
I have a plugin PaypalIpn in the Plugin Folder. The Plugin has a controller InstantPaymentNotificationsController and some actions inside.
If I try to access directly the plugin's controller with /paypal_ipn/instant_payment_notifications Cake says the there is no Paypal Controller.
Well, I added a route:
Router::connect('/paypal_ipn/:action/*', array( 'plugin' => 'paypal_ipn', 'controller' => 'instant_payment_notifications', 'action' => 'index'));
and surprise the webserver freezes and this errors is fired in httpd.log
PHP Fatal error: Allowed memory size of -2147483648 bytes exhausted (tried to allocate 320596 bytes) in libCake2.3/Cake/Error/ErrorHandler.php on line 114
According to plugin's installation notes the route should be:
Router::connect('/paypal_ipn/process',
array('plugin' => 'paypal_ipn',
'controller' => 'instant_payment_notifications',
'action' => 'process'
)
);
This is not what you have.
Also, be sure you have the latest version. The article on Bakery is from 2009 and is about a very old version.

Resources