mirror of
https://github.com/nextcloud/server.git
synced 2026-06-08 16:26:59 -04:00
Merge pull request #13269 from owncloud/issue/13211-cache-array-implementation
Add an array implementation of cache and use it if we are not debugging
This commit is contained in:
commit
8eb804b1f6
3 changed files with 89 additions and 1 deletions
71
lib/private/memcache/arraycache.php
Normal file
71
lib/private/memcache/arraycache.php
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2015 Joas Schilling <nickvergessen@owncloud.com>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace OC\Memcache;
|
||||
|
||||
class ArrayCache extends Cache {
|
||||
/** @var array Array with the cached data */
|
||||
protected $cachedData = array();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get($key) {
|
||||
if ($this->hasKey($key)) {
|
||||
return $this->cachedData[$key];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function set($key, $value, $ttl = 0) {
|
||||
$this->cachedData[$key] = $value;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function hasKey($key) {
|
||||
return isset($this->cachedData[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function remove($key) {
|
||||
unset($this->cachedData[$key]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function clear($prefix = '') {
|
||||
if ($prefix === '') {
|
||||
$this->cachedData = [];
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($this->cachedData as $key => $value) {
|
||||
if (strpos($key, $prefix) === 0) {
|
||||
$this->remove($key);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
static public function isAvailable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ class Factory implements ICacheFactory {
|
|||
} elseif (Memcached::isAvailable()) {
|
||||
return new Memcached($prefix);
|
||||
} else {
|
||||
return new Null($prefix);
|
||||
return new ArrayCache($prefix);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
17
tests/lib/memcache/arraycache.php
Normal file
17
tests/lib/memcache/arraycache.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (c) 2015 Joas Schilling <nickvergessen@owncloud.com>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace Test\Memcache;
|
||||
|
||||
class ArrayCache extends Cache {
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->instance = new \OC\Memcache\ArrayCache('');
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue