This document discusses caching templates in Template Toolkit to improve performance. It describes how to profile templates to identify optimization opportunities. Implementing caching reduced the total request processing time by 4.9 times and accelerated template rendering by 20 times. The Template::Context::Cacheable module provides caching capabilities and is available on GitHub.
7. Ìîäóëü äëÿ êýøèðîâàíèÿ
use Template : : C o n t e x t : : C a c h e a b l e ;
Template : : C o n t e x t : : C a c h e a b l e : : c o n f i g u r e _ c a c h i n g (
SRS : : Cache : : Memcached : : get ,
SRS : : Cache : : Memcached : : put ,
);
$Template : : C o n t e x t : : C a c h e a b l e : : DEBUG = 1 ;
8. Êàê ýòî âûãëÿäèò â øàáëîíàõ
index.html:
[% PROCESS index_reg_bar.inc
lang = lang
pricegroup = pricegroup
__cache_time = -1
%]
12. Ðåçóëüòàò...
Server Hostname: www1.reg.ru
Server Port: 80
Document Path: /
Document Length: 121176 bytes
Concurrency Level: 1
Time taken for tests: 9.524 seconds
Total transferred: 36445800 bytes
HTML transferred: 36352800 bytes
Requests per second: 31.50 [#/sec] (mean)
Time per request: 31.746 [ms] (mean)
Transfer rate: 3737.15 [Kbytes/sec] received
13. Ðåçóëüòàò...
Óìåíüøèëè îáùåå âðåìÿ îáðàáîòêè çàïðîñà â 4.9
ðàçà;
Óñêîðèëè îáðàáîòêó øàáëîíà â 20 ðàç;