Completed
Pull Request — release-2.1 (#3778)
by Martyn
07:41
created
Sources/CacheAPI-sqlite.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
    * @var string The path to the current $cachedir directory.
25 25
    */
26 26
   private $cachedir		= null;
27
-  private $cacheDB		= null;
27
+  private $cacheDB = null;
28 28
   private $cacheTime	= null;
29 29
 
30 30
 	public function __construct()
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 		// Set our default cachedir.
37 37
 		$this->setCachedir();
38 38
 
39
-		$database = $this->cachedir.'/'.'SQLite3Cache.db3';
39
+		$database = $this->cachedir . '/' . 'SQLite3Cache.db3';
40 40
 
41 41
 		$this->cacheDB = new SQLite3($database);
42 42
 		$this->cacheDB->busyTimeout(1000);
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 			$this->cacheDB->exec('CREATE TABLE cache (key text unique, value blob, ttl int);');
45 45
 			$this->cacheDB->exec('CREATE INDEX ttls ON cache(ttl);');
46 46
 		}
47
-		$this->cacheTime	= time();
47
+		$this->cacheTime = time();
48 48
 
49 49
 	}
50 50
 
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function getData($key, $ttl = null)
68 68
 	{
69
-		$ttl		= time();
70
-		$query	= 'SELECT value FROM cache WHERE key = \''.$this->cacheDB->escapeString($key).'\' AND ttl >= '.$ttl.' LIMIT 1';
69
+		$ttl = time();
70
+		$query = 'SELECT value FROM cache WHERE key = \'' . $this->cacheDB->escapeString($key) . '\' AND ttl >= ' . $ttl . ' LIMIT 1';
71 71
 		$result	= $this->cacheDB->query($query);
72 72
 
73 73
 		$value		= null;
74
-		while($res = $result->fetchArray(SQLITE3_ASSOC)) { 
74
+		while ($res = $result->fetchArray(SQLITE3_ASSOC)) { 
75 75
 			$value = $res['value'];
76 76
 		}
77 77
 
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
 	public function putData($key, $value, $ttl = null)
85 85
 	{
86 86
 
87
-		$ttl		= $this->cacheTime + $ttl;
88
-		$query	= 'REPLACE INTO cache VALUES (\''.$this->cacheDB->escapeString($key).'\', \''.$this->cacheDB->escapeString($value).'\', '.$this->cacheDB->escapeString($ttl).');';
89
-		$result	= $this->cacheDB->exec($query);
87
+		$ttl = $this->cacheTime + $ttl;
88
+		$query = 'REPLACE INTO cache VALUES (\'' . $this->cacheDB->escapeString($key) . '\', \'' . $this->cacheDB->escapeString($value) . '\', ' . $this->cacheDB->escapeString($ttl) . ');';
89
+		$result = $this->cacheDB->exec($query);
90 90
 
91 91
 		return $result;
92 92
 	}
@@ -97,8 +97,8 @@  discard block
 block discarded – undo
97 97
 	public function cleanCache($type = '')
98 98
 	{
99 99
 
100
-		$query	= 'DELETE FROM cache;';
101
-		$result	= $this->cacheDB->exec($query);
100
+		$query = 'DELETE FROM cache;';
101
+		$result = $this->cacheDB->exec($query);
102 102
 
103 103
 		return $result;
104 104
 
Please login to merge, or discard this patch.