Blog

MODx Chunk Cache Plugin

Oct
22

I needed to cache a chunk as a file so that another application (an ecommerce store) could include that file as well. I wrote this plugin that does that:

PHP:
  1. $chunks = array('StoreMenu'); // array of chunks that need to be cached
  2. foreach($chunks as $v)
  3. {
  4.   $res = $modx->db->select("snippet","modx_site_htmlsnippets","name = '$v'");
  5.   if($modx->db->getRecordCount($res))
  6.   {
  7.     $output = $modx->db->getValue($res)
  8.     $fh = fopen($modx->config['base_path'].$v.'.html','w');
  9.     fwrite($fh,$output);
  10.     fclose($fh);
  11.   }
  12. }

Configure this chunk to have the OnChunkFormSave system event an whenever a chunk is saved it will write the specified chunks to the file system.

Share With Friends
  • Print
  • Facebook
  • FriendFeed
  • Google Bookmarks
  • Sphinn
  • SphereIt
  • Digg
  • del.icio.us
  • Mixx
  • Fark
  • HackerNews
  • Reddit
  • StumbleUpon
  • Suggest to Techmeme via Twitter
  • Technorati
  • Twitter
  • Yahoo! Buzz

Related Posts


Comment Here » 261 views
Posted in: MODx

Comments »

Allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

No comments yet.

« New Tool: MODx Snippet Call2PHP | cPanel Bandwidth Checking Script »