tommy351/hexo — pull request #637 by tommy351 (2014-05-23 09:00:21+00:00)
Title: Fragment cache

Add fragment cache to improve the performance of file generating. This concept is stolen from [Ruby on Rails](http://guides.rubyonrails.org/caching_with_rails.html#fragment-caching). The cache will be only enabled in generating mode.

**New helper**: `fragment_cache(id, fn)`

``` js
<%- fragment_cache('footer', function(){
return '

';
}); %>
```

**Partial cache**

A new option `cache` will be added to `partial` helper. This is a shortcut to `fragment_cache` helper. For example:

``` js
<%- partial('footer', {}, {cache: true}) %>
```

yields:

``` js
<%- fragment_cache('footer', function(){
return partial('footer', {});
}) %>
```

The effect of fragment cache is remarkable. I used `fragment_cache` helper in sidebar to reduce database queries. It only took less than 10 seconds to generate 1000+ static files. The original elapsed time is 10 minutes, which means is at least 60 times faster.