This File adapter provides basic support for write, read, delete and clear cache functionality, as well as allowing the first four methods to be filtered as per the Lithium filtering system. The File adapter is a very simple cache, and should only be used for prototyping or for specifically caching _files_. For more general caching needs, please consider using a more appropriate cache adapter. This adapter does *not* provide increment/decrement functionality. For such functionality, please use a more approrpiate cache adapter. This adapter does *not* allow multi-key operations for any methods. The path that the cached files will be written to defaults to LITHIUM_APP_PATH/resources/tmp/cache, but is user-configurable on cache configuration. Note that the cache expiration time is stored within the first few bytes of the cached data, and is transparently added and/or removed when values are stored and/or retrieved from the cache.
See also: lithium\storage\cache\adapter
Inheritance: extends lithium\core\Object
 public function testWriteDefaultCacheExpiry()
 {
     $file = new File(array('expiry' => '+1 minute'));
     $key = 'default_keykey';
     $data = 'data';
     $time = time() + 60;
     $closure = $file->write($key, $data);
     $this->assertTrue(is_callable($closure));
     $params = compact('key', 'data');
     $result = $closure($file, $params, null);
     $expected = 25;
     $this->assertEqual($expected, $result);
     $this->assertTrue(file_exists(Libraries::get(true, 'resources') . "/tmp/cache/{$key}"));
     $this->assertEqual(file_get_contents(Libraries::get(true, 'resources') . "/tmp/cache/{$key}"), "{:expiry:{$time}}\ndata");
     $this->assertTrue(unlink(Libraries::get(true, 'resources') . "/tmp/cache/{$key}"));
     $this->assertFalse(file_exists(Libraries::get(true, 'resources') . "/tmp/cache/{$key}"));
 }
Exemple #2
0
 public function testIncrementWithScope()
 {
     $adapter = new File(array('scope' => 'primary'));
     $this->File->write(array('primary_key1' => 5));
     $this->File->write(array('key1' => 10));
     $expected = 6;
     $result = $adapter->increment('key1');
     $this->assertEqual($expected, $result);
     $expected = array('key1' => 6);
     $result = $adapter->read(array('key1'));
     $this->assertEqual($expected, $result);
 }