Neevo Public API
  • Namespace
  • Class
  • Tree

Namespaces

  • Neevo
    • Cache
    • Drivers
    • Nette
  • PHP

Classes

  • FileStorage
  • MemcacheStorage
  • MemoryStorage
  • SessionStorage

Interfaces

  • StorageInterface
 1 <?php
 2 /**
 3  * Neevo - Tiny database layer for PHP. (http://neevo.smasty.net)
 4  *
 5  * This source file is subject to the MIT license that is bundled
 6  * with this package in the file license.txt.
 7  *
 8  * Copyright (c) 2012 Smasty (http://smasty.net)
 9  *
10  */
11 
12 namespace Neevo\Cache;
13 
14 
15 /**
16  * File cache storage.
17  * @author Smasty
18  */
19 class FileStorage implements StorageInterface {
20 
21 
22     /** @var string */
23     private $filename;
24 
25     /** @var array */
26     private $data = array();
27 
28 
29     public function __construct($filename){
30         $this->filename = $filename;
31         $this->data = (array) unserialize(@file_get_contents($filename));
32     }
33 
34 
35     public function fetch($key){
36         return array_key_exists($key, $this->data) ? $this->data[$key] : null;
37     }
38 
39 
40     public function store($key, $value){
41         if(!array_key_exists($key, $this->data) || $this->data[$key] !== $value){
42             $this->data[$key] = $value;
43             @file_put_contents($this->filename, serialize($this->data), LOCK_EX);
44         }
45     }
46 
47 
48     public function flush(){
49         $this->data = array();
50         return @file_put_contents($this->filename, serialize($this->data), LOCK_EX);
51     }
52 
53 
54 }
55 
56 
Neevo Public API API documentation generated by ApiGen 2.8.0