Skip to content
Snippets Groups Projects
Commit fa8c81af authored by efalcy's avatar efalcy
Browse files

Merge branch 'hotline_cache_key_force_string' into 'master'

force cache key to string

See merge request !63
parents d10bde1f f60e05df
Branches
1 merge request!63force cache key to string
Pipeline #30994 passed with stage
in 54 seconds
......@@ -94,7 +94,7 @@ class Storm_Cache {
}
public function memoize($key, $callback) {
public function memoize(string $key, $callback) {
if(!$this->_enabled)
return $callback();
......@@ -124,28 +124,28 @@ class Storm_Cache {
}
public function load($key) {
public function load(string $key) {
return $this->unserialize($this->getCache()->load($this->addSeedToKey($key)));
}
public function save($data, $key){
public function save($data,string $key){
return $this->getCache()->save($this->serialize($data), $this->addSeedToKey($key));
}
public function remove($key){
public function remove(string $key) {
return $this->getCache()->remove($this->addSeedToKey($key));
}
public function test($key){
public function test(string $key){
return $this->getCache()->test($this->addSeedToKey($key));
}
public function addSeedToKey($key) {
return $this->_getRealSeed() . '_' . md5(json_encode([$key]));
public function addSeedToKey(string $key) {
return $this->_getRealSeed() . '_' . md5($key);
}
......@@ -178,5 +178,3 @@ class Storm_Cache {
return $this;
}
}
?>
\ No newline at end of file
......@@ -45,7 +45,7 @@ class Storm_CacheTest extends PHPUnit_Framework_TestCase {
$this->_cache->save('too much', 'minions');
$this->assertEquals('too much',
$this->_backend->load('kevin_' . md5(json_encode(['minions']))));
$this->_backend->load('kevin_' . md5('minions')));
}
......@@ -58,7 +58,7 @@ class Storm_CacheTest extends PHPUnit_Framework_TestCase {
$this->_cache->save('groo', 'master');
$this->assertEquals('groo',
$this->_backend->load($generated_seed.'_'.md5(json_encode([ 'master']))));
$this->_backend->load($generated_seed.'_'.md5('master')));
}
......@@ -84,4 +84,4 @@ class Storm_CacheTest extends PHPUnit_Framework_TestCase {
$generated_seed = $this->_backend->load('ban_ana');
$this->assertContains('ban_ana_', $generated_seed);
}
}
\ No newline at end of file
}
......@@ -43,7 +43,7 @@ class Storm_Test_VolatileCacheTest extends Storm_Test_ModelTestCase {
public function cachedIncrementCounter() {
return $this->_cache->memoize(['key'], [$this, 'incrementCounter']);
return $this->_cache->memoize(json_encode(['key']), [$this, 'incrementCounter']);
}
......@@ -69,5 +69,3 @@ class Storm_Test_VolatileCacheTest extends Storm_Test_ModelTestCase {
$this->assertEquals(0, $this->cachedIncrementCounter());
}
}
?>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment