You are viewing the PKP Support Forum | PKP Home Wiki

Output caching

OJS development discussion, enhancement requests, third-party patches and plug-ins.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
Developer Resources:

Documentation: The OJS Technical Reference and the OJS API Reference are both available from the OJS Documentation page.

Git: You can access our public Git Repository here. Comprehensive Git usage instructions are available on the wiki.

Bugzilla: You can access our Bugzilla report tracker here.

Search: You can use our Google Custom Search to search across our main website, the support forum, and Bugzilla.

Questions and discussion are welcome, but if you have a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a technical support question, try the OJS Technical Support subforum.

Output caching

Postby christo » Tue Dec 04, 2007 5:32 am


What is the best way to handle simple output caching with OJS? I am looking to achieve something similar to what can be done with PEAR::CACHE_LITE. I've had a look at the FileCache object, but am not 100% sure that i have got it correctly. Could anyone give me a short example of how to go about output caching with the OJS 2 framework?

Thanks in advance.
Posts: 22
Joined: Mon Jan 09, 2006 12:04 am
Location: Grahamstown, South Africa

Re: Output caching

Postby asmecher » Tue Dec 04, 2007 1:38 pm

Hi christo,

I'd suggest having a look at the current CVS version (which will be released as OJS 2.2) -- there is simple output caching implemented in it. Have a look at the web_cache and web_cache_hours settings in config.inc.php. Only certain pages are cached, e.g. the home page and a few others that are most frequently accessed.

Keep in mind, of course, that this will only work for sites that aren't using dynamic content such as banner ads on those pages.

Alec Smecher
Public Knowledge Project Team
Posts: 10015
Joined: Wed Aug 10, 2005 12:56 pm

Re: Output caching

Postby christo » Thu Dec 27, 2007 3:06 am

Here is some code if there is anyone else wanting to do this. It is based on the slightly OJS 2.1 codebase.

Code: Select all
$cacheManager =& CacheManager::getManager();

$cache = $cacheManager->getFileCache('page', /* this is the name of the group of items you want to cache - existing examples are 'journalSettings' and 'country'*/
                                                           $cacheId . "-" . Locale::getLocale() , /* this is specific to this particular instance which you are caching */
                                                           array('this','_cacheMiss') ); /* this is a function which is called to populate your cache. I cheated because i wasnt quite sure how to pass arguments to this function, so i just handled the caching procedurally below (this is probably not the best way to do it! */

if(is_null($cache->cache)){   //we don't have an existing cache, we need to renew it.
   //handle caching
   $contents = time(); //for the case of this example lets just use the timestamp...
echo $cache->getContent(); //spit out the result.

You can flush/clear the cache with $cache->flush() (this will only delete the cache for the file with the specific cacheId)

- have a look at Classes/User/CountryDAO.inc.php for a more in-depth example.
- As you will see in that example, the CacheManager can cache objects as well as variables. (which is useful).

..hope that helps someone....
Posts: 22
Joined: Mon Jan 09, 2006 12:04 am
Location: Grahamstown, South Africa

Return to OJS Development

Who is online

Users browsing this forum: No registered users and 1 guest