From de6e5fb884318288693f8c4821fda6942fdd50a6 Mon Sep 17 00:00:00 2001 From: "Dr. Kibitz" Date: Sat, 20 Jul 2013 13:22:43 -0700 Subject: [PATCH] Added MetadataCacheInclude --- src/Tonic/MetadataCacheInclude.php | 57 ++++++++++++++++++++++++++++++ web/dispatch.php | 1 + 2 files changed, 58 insertions(+) create mode 100644 src/Tonic/MetadataCacheInclude.php diff --git a/src/Tonic/MetadataCacheInclude.php b/src/Tonic/MetadataCacheInclude.php new file mode 100644 index 0000000..7e7f4a8 --- /dev/null +++ b/src/Tonic/MetadataCacheInclude.php @@ -0,0 +1,57 @@ +filename = $filename; + } + + /** + * Is there already cache file + * @return boolean + */ + public function isCached() + { + return is_readable($this->filename); + } + + /** + * Load the resource metadata + * @return str[] + */ + public function load() + { + return include $this->filename; + } + + /** + * Save resource metadata to disk + * @param str[] $resources Resource metadata + * @return boolean + */ + public function save($resources) + { + return file_put_contents($this->filename, 'filename); + } + + public function __toString() + { + return 'Metadata for '.count($this->load()).' resources stored in file "'.$this->filename.'" at '.date('r', filemtime($this->filename)); + } + +} diff --git a/web/dispatch.php b/web/dispatch.php index f39c858..ead40d5 100644 --- a/web/dispatch.php +++ b/web/dispatch.php @@ -15,6 +15,7 @@ #'mount' => array('Tyrell' => '/nexus'), // mount in example resources at URL /nexus #'cache' => new Tonic\MetadataCacheFile('/tmp/tonic.cache') // use the metadata cache #'cache' => new Tonic\MetadataCacheAPC // use the metadata cache + #'cache' => new Tonic\MetadataCacheInclude('/tmp/tonic-cache.php') // use the metadata cache ); $app = new Tonic\Application($config);