Manually force cache purge

Discussion forum for MOD Writers regarding MOD Development.
Locked
amochohan
Registered User
Posts: 92
Joined: Tue Dec 11, 2007 2:59 pm

Manually force cache purge

Post by amochohan »

I'm currently caching many of my SQL queries to improve performance on our website. This is working perfectly at the moment.

One example of where i'm using this is to cache the comments made for any given page. What I'd like to do though is when a user posts a new comment (commenting system all written with PHPBB3 DBAL) the comment gets inserted (which it does at the moment) and then it fetches a current list of the comments, rather than the one's within the sites cache.

Is there a way of forcing the cache for that particular query to be updated, rather than having to wait the specified cache validity time?

I assume there is, as phpBB must cache topics/threads in the forum and then do a similar thing when a user makes a new post to a thread.

User avatar
A_Jelly_Doughnut
Former Team Member
Posts: 34457
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run
Contact:

Re: Manually force cache purge

Post by A_Jelly_Doughnut »

It depends on which caching method you are using. Generally, you'd do $cache->destroy('_sql', POSTS_TABLE); for instance.
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish

amochohan
Registered User
Posts: 92
Joined: Tue Dec 11, 2007 2:59 pm

Re: Manually force cache purge

Post by amochohan »

Thanks for the responce,

To cache the query - i'm using:

Code: Select all

$cache_length = 300;
$result = $db->sql_query($sql, $cache_length);
But this is for a custom table that isn't part of the phpBB table-set, and to make things worse it uses two or more tables in the query. For example:

Code: Select all

$sql='SELECT whatever FROM table1, table2, table3 WHERE (table1.somevalue=table2.somevalue) AND (table2.somevalue=table3.somevalue) AND (table1.somethingelse=1)
So, how could I destroy the cache for this sort of query? So it deletes the cached query for just that particular query

Thank's for your quick reply :)

amochohan
Registered User
Posts: 92
Joined: Tue Dec 11, 2007 2:59 pm

Re: Manually force cache purge

Post by amochohan »

Anyone???

Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 25658
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: Manually force cache purge

Post by Paul »

The second parametrof the destroy function is the table name, so that would be in your case array('table1', 'table2') ;)
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development

amochohan
Registered User
Posts: 92
Joined: Tue Dec 11, 2007 2:59 pm

Re: Manually force cache purge

Post by amochohan »

Hi Paul,

The thing is, I am trying to cache comments made by any particular user with a where clause.

Basically, I created a new profile page so that users can have comments left on their page.

So for example, when a user has a new comment left on their page, it will destroy the cache for the query, but ONLY where the 'where' clause is set.

Does that make sense??? :lol:

So, if the table is called 'profileComments', it won't simply destroy the cache for the entire profileComments table, but just the cached query results for 'SELECT * FROM profileComments WHERE user_id=whatever'

(Crude example, but hope that helps explain)

Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 25658
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: Manually force cache purge

Post by Paul »

No, thats not possible. It destroyes everything or nothing :).
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development

Locked

Return to “[3.0.x] MOD Writers Discussion”