Posts in category caching

Dynamic content caching, 0.2 and analytics

As you all may have noticed we busted the 0.2 deadline again. Some things got in the way, and in reality we are probably a month from tagging the 0.2 milestone. We will keep working towards it tho, and any contributions are welcome.

Lepton now has basic (and very beta) support for dynamic content caching, that is storing data in the filesystem and database rather than regenerating it on each request. This is good and very useful for f.ex. galleries where images change often, dynamically generated avatars, and also any textual content that takes time to generate.

Using it is easy, just call the static get() and set() methods of the FsCache class; first attempt to get() it, and if that fails just generate the content and then set() it:

if (!FsCache::get('images/'.$id)) {
   $i = Graphics::load('images/'.$id);
   $i->resize(140,140,ImageCanvas::KEEP_CROP);
   $i->output('image/png');
   $d = $i->output('image/png', 75, true);
   FsCache::set('images/'.$id, 'image/png', $d);
}

Easy to use, albeit still a bit gronky. The handy part tho is that the get() call will handle all the output, including setting the content type.

There is now also support for Google Analytics using the ganalytics library. You can read more about that in the readme file.