Re: [SMARTY] About caching (2)
| From: | Monte Ohrt | Date: | Thu, 26 Dec 2002 21:44:17 +0000 |
| Subject: | Re: [SMARTY] About caching (2) | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-6948@lists.php.net to get a copy of this message | ||
Sometimes we handle things like this at the application level. For
instance, The front page is created with many SQL queries, and cached
indefinately. When an action happens that affects the content of the
front page (such as an article being changed, etc.), a file is created
in a dropfile directory. This file is timestamped and contains a path to
the directory that needs files cleared from (such as smarty/cache). A
separate cron job tests the dropfile directory for new files every
minute, and spawns and detaches a file cleaning job for each one it
finds. This way you get maximum benefit from your cache (stay cached
until absolutely need changing), and you can also schedule future cache
clearing with a future timestamp (such as an article being published for
later that night.) If you use smarty cache groups, you can get more
granularity with your clearing since you can specify a subdiretory.
Also for those of you using MySQL, 4.x has a query caching feature that
will help a lot with repeated queries, with or without Smarty.
Monte
On Thu, 2002-12-26 at 15:17, Peter Billen wrote:
> Hi,
>
> Another caching question for you :)
>
> Imagine you have a site that contains several pages (let’s say 1000
> pages) and that each page is generated by +/- 50 (do not ask me why :p)
> database queries and that you cache each page (so you have 1000 unique
> cache files). So actually, after the first click on page x, your total
> dbase queries = 0. Now imagine that you have changed something in the
> database, something that is shown on (almost) EVERY of those 1000 pages.
>
> How do you handle with such situations? The only solution I can find is
> deleting/flushing the whole cache directory, but then, you have to
> re-query everything again (as in 1000 * 50 queries) on the first click.
>
> An optimal solution would be that you can cache each query. So after
> editing something in the database, you ONLY have to re-query THAT query,
> and not:
>
> → 1000 x that query for each page
> → on each page: 49 x the others queries, who haven’t changed!
>
> Any ideas?
>
> Thanks,
>
> Peter
--
Monte Ohrt <monte@ispi.net>