Version 0.2.0
- Allow caching fragment of pages.
- Cache single objects.
- Cache one big object made of smaller ones (Cascade Caching).
- Cache on disk.
- Cache with Redis.
Example to cache posts with Laravel.
Cache single object
In your view
<?php
use RussianDollCaching\Cache;
use RussianDollCaching\DiskCache;
$cache = new Cache(new DiskCache());
?>
<?php foreach($posts->get() as $post): ?>
<?php $cache->cache($post, function() use ($post){ ?>
some code
<?php }); ?>
<?php endforeach; ?>
Cascade Caching
In your model
public static function lastUpdated(){
return self::orderBy('updated_at', 'DESC')->select('id', 'updated_at')->first();
}
In your view
<?php
use RussianDollCaching\Cache;
use RussianDollCaching\DiskCache;
$cache = new Cache(new DiskCache());
?>
<?php $cache->cache(['posts', \App\Post::lastUpdated()], function() use ($cache, $posts){ ?>
<?php foreach($posts->get() as $post): ?>
<?php $cache->cache($post, function() use ($post){ ?>
some code
<?php }); ?>
<?php endforeach; ?>
<?php }); ?>
Example to cache posts with Laravel.
Cache single object
In your view
<?php
use RussianDollCaching\Cache;
use RussianDollCaching\RedisCache;
$cache = new Cache(new RedisCache());
?>
<?php foreach($posts->get() as $post): ?>
<?php $cache->cache($post, function() use ($post){ ?>
some code
<?php }); ?>
<?php endforeach; ?>
Cascade Caching
In your model
public static function lastUpdated(){
return self::orderBy('updated_at', 'DEST')->select('id', 'updated_at')->first();
}
In your view
<?php
use RussianDollCaching\Cache;
use RussianDollCaching\RedisCache;
$cache = new Cache(new RedisCache());
?>
<?php $cache->cache(['posts', \App\Post::lastUpdated()], function() use ($cache, $posts){ ?>
<?php foreach($posts->get() as $post): ?>
<?php $cache->cache($post, function() use ($post){ ?>
some code
<?php }); ?>
<?php endforeach; ?>
<?php }); ?>
The code for RussianDollCaching is distributed under the terms of the GNU/GPL V3 license (see LICENSE).