Caching of variables

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
onli
Regular
Posts: 3044
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Caching of variables

Post by onli »

Hi
I'm trying to write a autotitle-plugin that automatically insert the title-tag into links. Seems to work well, but of course fetching the foreign page and grep the title is something that shouldn't be done every time a page is viewed - a cache is needed.

Is there a standard-cache serendipity(-plugins) may use, a global implementation? I checked the entryproperties-plugin and it seems to me like this is caching using the db, which don't seem too pretty to me. I got a working solution using APC:

Code: Select all

function get_cached_title($url) {
    return apc_fetch($url);
}

function cache_title($url, $title) {
    return apc_store($url, $title);
} 
But it's not nice to depend on something not default.

Declaring a class-array as static won't work as persistent cache, will it? So, which way to go?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Caching of variables

Post by garvinhicking »

Hi!

Some plugins use the PEAR Cache_Lite (bundled with s9y), but I'm not sure if that applies to your application.

What you actually might want to do is to make your plugin generally cache the output of the blog entry/extended entry, just like nl2br and the emoticate plugins do to one-time parse an entry, and then that one-time parsed representation is fetched by the entryproperties plugin. When entryproperties is not installed, the plugin falls back to execute every time.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
onli
Regular
Posts: 3044
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Caching of variables

Post by onli »

Hi Garvin
when testing nl2p 0.1 entryproperties was installed, but the performance sucked anyway. I don't think that the cache worked too well. Seemed to me like the operation was done in the background, despite the cache. A pity the frontpage of my local-installation is broken (apc didn't work with lighttpd and apache don't render the php-code of the frontpage at the moment) so I can't test it again.

I'll try Cache_Lite - although it seems like it is made for caching containers, maybe it works well enough. Thanks for the hint.
sincerely
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Caching of variables

Post by garvinhicking »

Hi!

Indeed, nl2br does not cache by default. But the serendipity_event_trackexits plugin contains this.

Look out for "cachable_events" and "frontend_display_cache" inside the sourcecode.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
onli
Regular
Posts: 3044
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Caching of variables

Post by onli »

Ah, that's an explanation, thanks. But using Cache_Lite works pretty well and is really easy, especially because cache-simple is a working example (and the difference to apc isn't big when using this way). Just one last thing: Is it intention to use a Cache_Lite version from 2005?
sincerely
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Caching of variables

Post by garvinhicking »

Hi!

I think Cache_Lite hasn't been maintained that much in the past, is there a newer version with important changes?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
onli
Regular
Posts: 3044
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Caching of variables

Post by onli »

I stumbled upon the possibility of marking cache-lifetime to 0 which means unlimited since 1.6. But cause that would only be really useful in combination with memory-caching, which ain't persistent, that is for the current situation no longer important.

edit: I'm a bit confused about the differences of changelog and given plugin, dating to 2005 and saying verson 1.3. The feature-description " - hashed cache directory structure with the choice of the level" is from the changelog from 1.4 beta1, but the option exists in the file provided by serendipity. Same is true for the random-cleanup.

Despite the confusion, there are some bugfixes, so probably we should test the newest version 1.7.7.
sincerely
Post Reply