NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP caching (not opcode)

Patrick May patrick at hexane.org
Thu Jul 17 17:52:21 EDT 2008


Hello,

I'm working on a PHP cache library, and I wanted to check in and see what
folks thought.

Usually, you have many different front end views that you will want to
cache.  These may pull from multiple datasources in odd ways.  Far away from
the front end, there is backend CMS, either a tool like Wordpress or Drupal,
or a custom tool.  Generally, I find myself managing caches by:

1. Putting the code that generates the cache into the front end, since it is
the design that dictates which pieces of information should be grouped
together.
2. Putting a very small amount of code in the back end which causes the
cache to be deleted on the appropriate CRUD operations.  CMS's are
complicated enough as they are, and I don't want to clutter them up more
then necessary.

The hard part is creating the association between the front and back end.
What I want to do is to use *tags* to create this association, and to break
caches.

It works something like this:

<?php
function an_expensive_operation($arg1, $arg2) {
    ....
}

cache_set_dir('/tmp/www/cache');

// this will either run the callback and cache
// the return value and output, or just spit
// out the output and return value
// function cache( $callback, $params, $unique_name, $flags ) {...};
cache(
  'an_expensive_operation',
  array($value1, $value2),
  'run_an_expensive_operation_on_the_home_page',
  array('on_save', 'on_update', 'on_monday')
);

// any of these calls will cause the cache to be deleted,
// and force the cached function above to be re-run
break_cache('run_an_expensive_operation_on_the_home_page');
break_cache('on_save');
break_cache('on_update');
break_cache('on_monday');
break_cache('on_tuesday', 'on_monday');
?>

Does this sound similar to any existing library / tool, either for PHP or
for any other platform?  Does this sound like a useful library?

Thanks for your feedback!

Cheers,

Patrick


-- 
Patrick May
135 Oak Street
New York, NY 11222
+1 (347) 232-5208
patrick at hexane.org
http://www.hexane.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20080717/9ffd352e/attachment.html>


More information about the talk mailing list