Ticket #112 (new enhancement)
better vardata caching by implementing pre-check/post-check algo
| Reported by: | moo | Owned by: | moo |
|---|---|---|---|
| Priority: | major | Milestone: | 2.0.0 |
| Component: | cacher | Version: | 2.0.0-dev |
| Keywords: | Cc: | ||
| PHP Version: | Application: | ||
| Need User Feedback: | no | Other Exts: | |
| SAPI: | Probability: | ||
| Blocking: |
Description (last modified by moo) (diff)
- Update API: xcache_isset($name [, $post_check_ttl])
Example usage:
<?php define(TMPDIR, '/tmp'); function load_abc_data() { $name = "abc_data"; $ttl = 120; // cache for 2 minutes $post_check_ttl = 60; // reload every 1 minutes, while other reader keep using the stale data if (!xcache_isset($name, $post_check_ttl)) { // it worth a lock here to avoid useless yet harmful concurrent load from any slow backend (backend=mysql here). $fp = fopen(TMPDIR . "/abc_data.lock", "w"); // only one worker update it and other keep on reading, if it's in post-check time $nb = xcache_isset($name) ? 0 : LOCK_NB; if (flock($fp, LOCK_EX | $nb)) { // check AGAIN after we get the lock if (!xcache_isset($name, $post_check_ttl)) { mysql_query .... and get $data xcache_set($name, $data, 120); fclose($fp); return $data; } else { fclose($fp); } } } return xcache_get($name); } ?>
See MSDN for Cache-Control pre-check/post-check algo
Change History
Note: See
TracTickets for help on using
tickets.

