Skip to content

Commit

Permalink
first pass before testing
Browse files Browse the repository at this point in the history
  • Loading branch information
rynop committed Jan 28, 2012
1 parent fc8cf79 commit 15973ec
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 268 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
.buildpath
.project
.settings
*~
55 changes: 0 additions & 55 deletions README

This file was deleted.

62 changes: 62 additions & 0 deletions README.md
@@ -0,0 +1,62 @@
# ViewMemcache

Store your view(s) to memcache. Allows easy distributed view invalidation and serving pages right from memcache via nginx (for example)

## Configuration

clone into APP/Plugin/ViewMemcache

Make an entry in APP/bootstrap.php for the 'view_memcache' engine:

```php
Cache::config('view_memcache', array(
'engine' => 'Memcache', //[required]
'duration'=> 1209600, //2 weeks [optional] You can conditionally set this in your controller and or action, see below
'probability'=> 100, //[optional]
'prefix' => 'VM_', //[optional] prefix every cache file with this string. If you change, make sure to update your nginx conf
'servers' => array(
'127.0.0.1:11211' // localhost, default port 11211
), //[optional]
'persistent' => true, // [optional] set this to false for non-persistent connections
'compress' => true, // [optional] compress data in Memcache (slower, but uses less memory)
));
```

Put this in APP/Controller/AppController.php or just in the controller you want to do caching in.

```php
var $helpers = array('ViewMemcache.ViewMemcache');
```

From controller (or beforeFilter(), or AppController::beforeFilter()) simply do:

```php
$viewMemcacheTimeout = <seconds> | <cache engine readable range, ex: '+30 days'>; //This is optional. If not set, will use
$enableViewMemcache = true;
$this->set(compact('viewMemcacheTimeout','enableViewMemcache'));
```

### nginx sample config

location / {
set $memcached_key "VM_:$request_uri";;
memcached_connect_timeout 2000;
memcached_read_timeout 2000;
memcached_pass 127.0.0.1:11211;
default_type text/html;
# if memcache throws one of the following errors fallback to PHP
error_page 404 502 504 = @fallback;
}

location @fallback{
root /var/www/demo.*.com/app/webroot;

try_files $uri $uri/ /index.php?$uri&$args;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_intercept_errors on;
}
35 changes: 35 additions & 0 deletions View/Helper/ViewMemcache.php
@@ -0,0 +1,35 @@
<?php
App::uses('AppHelper', 'View/Helper');

/**
*
* Store view to 'view_memcache' memcache storage engine config
*
* From controller simply do:
* $viewMemcacheTimeout = <seconds> | <cache engine readable range, ex: '+30 days'>
* $enableViewMemcache = true;
* $this->set(compact('viewMemcacheTimeout','enableViewMemcache'));
*
* You can also disable storing view to memcache by setting Configure::write('ViewMemcache.disable',true);
* @author rynop
*
* Based on https://github.com/salgo/cakephp-viewmemcache by salgo
*
*/
class ViewMemcache extends AppHelper {
function afterLayout() {
if (Configure::read('Cache.disable') || Configure::read('ViewMemcache.disable')) {
return true;
}

if (!empty($this->_View->viewVars['enableViewMemcache'] === true)) {
if (isset($this->_View->viewVars['viewMemcacheTimeout'])) {
Cache::set(array('duration' => $this->_View->viewVars['viewMemcacheTimeout'],null,'view_memcache')); //'+30 days' or seconds
}

Cache::write($this->request->here, $this->_View->output, 'view_memcache');
}

return true;
}
}
Empty file added View/Helper/empty
Empty file.
166 changes: 0 additions & 166 deletions libs/cache/view_memcache.php

This file was deleted.

7 changes: 0 additions & 7 deletions view_memcache_app_controller.php

This file was deleted.

7 changes: 0 additions & 7 deletions view_memcache_app_model.php

This file was deleted.

33 changes: 0 additions & 33 deletions views/helpers/view_memcache.php

This file was deleted.

0 comments on commit 15973ec

Please sign in to comment.