From be7245cb35c001efd11dca53fbb51943980f4886 Mon Sep 17 00:00:00 2001 From: fabien Date: Mon, 14 Dec 2009 07:05:06 +0000 Subject: [PATCH] changed the Array and String loaders to actually make use of the cache mechanism git-svn-id: http://svn.twig-project.org/trunk@178 93ef8e89-cb99-4229-a87c-7fa0fa45744b --- CHANGELOG | 1 + doc/03-Twig-for-Developers.markdown | 7 +++++++ lib/Twig/Loader/Array.php | 7 ++++++- lib/Twig/Loader/String.php | 7 ++++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index afa74ac..a9cd814 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 0.9.5-DEV + * changed the Array and String loaders to actually make use of the cache mechanism * included the default filter function definitions in the extension class files directly (Core, Escaper) * added the .. operator (as a syntactic sugar for the range filter when the step is 1) * added the in operator (as a syntactic sugar for the in filter) diff --git a/doc/03-Twig-for-Developers.markdown b/doc/03-Twig-for-Developers.markdown index 6df907b..24fed8a 100644 --- a/doc/03-Twig-for-Developers.markdown +++ b/doc/03-Twig-for-Developers.markdown @@ -150,6 +150,13 @@ Here a list of the built-in loaders Twig provides: [php] $loader = new Twig_Loader_Array($templates); +>**TIP** +>When using the `Array` or `String` loaders with a cache mechanism, you should +>know that a new cache key is generated each time a template content "changes" +>(the cache key being the source code of the template). If you don't want to +>see your cache grows out of control, you need to take care of clearing the old +>cache file by yourself. + ### Create your own Loader All loaders implement the `Twig_LoaderInterface`: diff --git a/lib/Twig/Loader/Array.php b/lib/Twig/Loader/Array.php index 2d3fbe7..c62f935 100644 --- a/lib/Twig/Loader/Array.php +++ b/lib/Twig/Loader/Array.php @@ -12,6 +12,11 @@ /** * Loads a template from an array. * + * When using this loader with a cache mehcanism, you should know that a new cache + * key is generated each time a template content "changes" (the cache key being the + * source code of the template). If you don't want to see your cache grows out of + * control, you need to take care of clearing the old cache file by yourself. + * * @package twig * @author Fabien Potencier * @version SVN: $Id$ @@ -78,6 +83,6 @@ class Twig_Loader_Array implements Twig_LoaderInterface */ public function isFresh($name, $time) { - return false; + return true; } } diff --git a/lib/Twig/Loader/String.php b/lib/Twig/Loader/String.php index 1c3eb1b..5fe451d 100644 --- a/lib/Twig/Loader/String.php +++ b/lib/Twig/Loader/String.php @@ -12,6 +12,11 @@ /** * Loads a template from a string. * + * When using this loader with a cache mechanism, you should know that a new cache + * key is generated each time a template content "changes" (the cache key being the + * source code of the template). If you don't want to see your cache grows out of + * control, you need to take care of clearing the old cache file by yourself. + * * @package twig * @author Fabien Potencier * @version SVN: $Id$ @@ -50,6 +55,6 @@ class Twig_Loader_String implements Twig_LoaderInterface */ public function isFresh($name, $time) { - return false; + return true; } } -- 1.7.2.5