Paginated caching, cleanup from update - how to solve?

I created a forum and we are implementing the apc and memcache caching solution to keep the database running.

I started to implement a cache level with keys such as "Categories :: getAll", and if I had user-specific data, I would add keys with things like user ID so that you get "User::getFavoriteThreads|1471". When the user added a new favorite stream, I would delete the cache key, and he recreated the record.

However, a problem arises here:

I wanted to cache threads in the forum. Simple enough, "Forum :: getThreads | $ iForumId". But ... With pagination, I would have to split this into multiple cache entries, for example

"Forum::getThreads|$iForumId|$iLimit|$iOffset".

Which is good until someone adds a new topic to the forum. Now I have to delete all the keys in "Forum::getThreads|$iForumId", no matter what the limit and offset.

What would be a good way to solve this problem? I would rather not go over all possible constraints and bias until I find something that no longer matches.

Thanks.

+5
source share
8 answers

You can also look at the cost of storing cache data in terms of your efforts and processor cost, compared to how your cache will buy.

, 80% , . , , .

. , , .

+5

: , . 50 .

, 90 . , , . , array_slice() .

, - , / : -)

, flungabunga, . , .

!

+7

, memcache (, ExtendedMemcache), , - .

ExtendedMemcache->set 3 ($strGroup, $strKey, $strValue) set, $strGroup $strKey , $strKey to $strValue memcache.

ExtendedMemcache, "deleteGroup", , , .

: http://pastebin.com/f566e913b , .

PS. , , memcache . .

+5

, . , . , . db , . db MyISAM, , db.

+2

, - , Forum::getThreads|$iForumId. PHP- , ,

$page = 2;
$threads_per_page = 25;
$start_thread = $page * $threads_per_page;

// Pull threads from cache (assuming $cache class for memcache interface..)
$threads = $cache->get("Forum::getThreads|$iForumId");

// Only take the ones we need
for($i=$start_thread; $i<=$start_thread+$threads_per_page; $i++)
{
    // Thread display logic here...
    showThread($threads[$i]);
}

, , , / .

+1

flungabunga: , . , , - memcache .

, , . , . ( , , !).

+1

, ​​, .

. , , , , .

+1

flungabunga:

- , "" . .

.

get seqno_mygroup
23

get mygroup23_mykey
<mykeydata...>
get mygroup23_mykey2
<mykey2data...>

"" :

incr seqno_mygroup

:

get seqno_mygroup
24

get mygroup24_mykey
...empty

...

+1

All Articles