Files
smarty/docs/en/programmers/caching/caching-groups.xml

110 lines
3.7 KiB
XML
Raw Normal View History

2004-04-13 11:47:32 +00:00
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<sect1 id="caching.groups">
<title>Cache Groups</title>
2004-04-13 12:14:17 +00:00
<para>
2006-09-27 00:54:40 +00:00
You can do more elaborate grouping by setting up
<parameter>$cache_id</parameter> groups. This is
accomplished by separating each sub-group with a vertical bar
<literal>|</literal> in the <parameter>$cache_id</parameter> value.
You can have as many sub-groups as you like.
2004-04-13 12:14:17 +00:00
</para>
2006-09-27 00:54:40 +00:00
<itemizedlist>
<listitem><para>
2005-12-10 08:55:20 +00:00
You can think of cache groups like a directory hierarchy. For instance, a
2006-09-27 00:54:40 +00:00
cache group of <literal>'a|b|c'</literal> could be thought of as the
directory structure <literal>'/a/b/c/'</literal>.
</para></listitem>
<listitem><para>
<literal>clear_cache(null,'a|b|c')</literal>
2006-02-18 11:53:24 +00:00
would be like removing the files
2006-09-27 00:54:40 +00:00
<literal>'/a/b/c/*'</literal>. <literal>clear_cache(null,'a|b')</literal>
would be like removing the files <literal>'/a/b/*'</literal>.
</para></listitem>
<listitem><para>
If you specify a
<link linkend="variable.compile.id"><parameter>$compile_id</parameter></link>
such as <literal>clear_cache(null,'a|b','foo')</literal> it is treated as
an appended cache group <literal>'/a/b/c/foo/'</literal>.
</para></listitem>
<listitem><para>
If you specify a template name such as
<literal>clear_cache('foo.tpl','a|b|c')</literal> then Smarty will attempt
to remove <literal>'/a/b/c/foo.tpl'</literal>.
</para></listitem>
<listitem><para>
You CANNOT remove a specified template name under
multiple cache groups such as <literal>'/a/b/*/foo.tpl'</literal>, the
cache grouping works
left-to-right ONLY. You will need to group your templates under a single
cache group heirarchy to be able to clear them as a group.
2006-09-27 00:54:40 +00:00
</para></listitem>
</itemizedlist>
<para>
Cache grouping should not be confused with your template directory
heirarchy, the cache grouping has no knowledge of how your templates are
structured. So for example, if you have a template structure like
2006-09-27 00:54:40 +00:00
<filename>themes/blue/index.tpl</filename> and you want to be able to
clear all the cache files for the <quote>blue</quote> theme, you will need
to create a cache group
structure that mimics your template file structure, such as
2006-09-27 00:54:40 +00:00
<literal>display('themes/blue/index.tpl','themes|blue')</literal>, then
clear them with
<literal>clear_cache(null,'themes|blue')</literal>.
</para>
2004-04-13 12:14:17 +00:00
<example>
2006-09-27 00:54:40 +00:00
<title>$cache_id groups</title>
2004-04-13 12:14:17 +00:00
<programlisting role="php">
2004-04-13 11:47:32 +00:00
<![CDATA[
<?php
require('Smarty.class.php');
$smarty = new Smarty;
$smarty->caching = true;
2005-09-13 16:14:31 +00:00
// clear all caches with 'sports|basketball' as the first two cache_id groups
$smarty->clear_cache(null,'sports|basketball');
2004-04-13 11:47:32 +00:00
// clear all caches with "sports" as the first cache_id group. This would
// include "sports|basketball", or "sports|(anything)|(anything)|(anything)|..."
2005-09-13 16:14:31 +00:00
$smarty->clear_cache(null,'sports');
2004-04-13 11:47:32 +00:00
// clear the foo.tpl cache file with "sports|basketball" as the cache_id
2005-09-13 16:14:31 +00:00
$smarty->clear_cache('foo.tpl','sports|basketball');
2005-09-13 16:14:31 +00:00
$smarty->display('index.tpl','sports|basketball');
2004-04-13 11:47:32 +00:00
?>
]]>
2004-04-13 12:14:17 +00:00
</programlisting>
</example>
2006-09-27 00:54:40 +00:00
2004-04-13 12:14:17 +00:00
</sect1>
2004-04-13 11:47:32 +00:00
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
2004-04-13 12:14:17 +00:00
-->