Re: [SMARTY] Deleting a specific cache id from a different smarty instance
| From: | Aliba Sora | Date: | Thu, 23 Jan 2003 08:42:52 +0000 |
| Subject: | Re: [SMARTY] Deleting a specific cache id from a different smarty instance | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7307@lists.php.net to get a copy of this message | ||
I was just running around with this idea on an admin portion of a site I'm
re-building from phplib to smarty. I've got to say, smarty has saved a LOT of
time!
The admin section actually manages two sites with some similar content. Some
of the events, FAQs and news items are the same across sites. When a new
item is added I needed to clear the cache for both sites.
Within the admin_site.conf file I added a [Dirs] section like so:
[Dirs]
Dom1CacheDir="/path/to/dom1/cache/"
Dom1TPLCacheDir="/path/to/dom1/templates_c/"
Dom2CacheDir="/path/to/dom2/cache/"
Dom2TPLCacheDir="/path/to/dom2/templates_c/"
AdminCacheDir="/path/to/admin/cache/"
...along with many other entries that proved useful later.
Then, in the script:
$DIRS = $conf->get("site.conf", "Dirs");
Of course $smarty is set to the admin directories as defined in my
setup_admin.php. When it comes time to clear templates or cache...
$smarty->cache_dir = $DIRS['Dom1CacheDir'];
$smarty->clear_cache(null, "faq");
$smarty->cache_dir = $DIRS['Dom2CacheDir'];
$smarty->clear_cache(null, "faq");
$smarty->cache_dir = $DIRS['AdminCacheDir'];
In this case, I switch the admin cache_dir to that of dom1 and then proceed to
clear all cache for the group 'faq'. Then switch to dom2, clear cache, and
finally restore it to the original admin cache dir. That's excessive, if you
have a cacheid then just clear that. I only do this because each page has a
list of all faqs at the bottom that would need to be regenerated, and it
clears the index as well.
The advantage this has over calling a new instance is reduced overhead yes,
but simplicity of adding a new site to the admin pages at anytime by just
adding a couple lines to clear the cache. Without having to add another
setup file, etc.
I didn't spend much time on this one so I'm sure there's a better way :)
On Tuesday 21 January 2003 17:28, Hoffman, Geoffrey wrote:
> I found
>
> // clear the cache for a particular cache id in an multiple-cache template
> $smarty->clear_cache("index.tpl","CACHEID");
>
> on the docs, but it appears that this is meant to be used at view-time,
> e.g. right before a 'display' is called.
>
> I'm wondering if there's an easy way to clear a cache id at database update
> time instead.
>
> The admin app I'm building will have a completely different instance of
> $smarty (technically, a $smarty_admin_app based on extending the smarty
> class), so it has different paths than the instance of $smarty_view_app)...
> I need to have the $smarty_admin_app trash a cacheid from the
> $smarty_view_app ... seems like I may have to roll my own PHP handler to do
> it, but was hoping to avoid that.
>
> Any suggestions would be most helpful.
>
> Regards-
> Geoff
>
> By the way, now that I've been using smarty for a while, it becomes more
> apparent with each hour I save what an awesome achievement it is.
> Rock on Monte!