Skip to content

Commit

Permalink
Fix that increment/decrement no longer work for XcacheEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
chinpei215 committed Mar 13, 2016
1 parent 6105714 commit 07bf626
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Cache/Engine/XcacheEngine.php
Expand Up @@ -77,10 +77,14 @@ public function write($key, $value)
{
$key = $this->_key($key);

if (!is_numeric($value)) {
$value = serialize($value);
}

$duration = $this->_config['duration'];
$expires = time() + $duration;
xcache_set($key . '_expires', $expires, $duration);
return xcache_set($key, serialize($value), $duration);
return xcache_set($key, $value, $duration);
}

/**
Expand All @@ -100,7 +104,12 @@ public function read($key)
if ($cachetime < $time || ($time + $this->_config['duration']) < $cachetime) {
return false;
}
return unserialize(xcache_get($key));

$value = xcache_get($key);
if (is_string($value) && !is_numeric($value)) {
$value = unserialize($value);
}
return $value;
}
return false;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/TestCase/Cache/Engine/XcacheEngineTest.php
Expand Up @@ -102,6 +102,7 @@ public function testReadAndWriteCache()
$expecting = '';
$this->assertEquals($expecting, $result);

// String
$data = 'this is a test of the emergency broadcasting system';
$result = Cache::write('test', $data, 'xcache');
$this->assertTrue($result);
Expand All @@ -110,6 +111,23 @@ public function testReadAndWriteCache()
$expecting = $data;
$this->assertEquals($expecting, $result);

// Integer
$data = 100;
$result = Cache::write('test', 100, 'xcache');
$this->assertTrue($result);

$result = Cache::read('test', 'xcache');
$this->assertSame(100, $result);

// Object
$data = (object)['value' => 'an object'];
$result = Cache::write('test', $data, 'xcache');
$this->assertTrue($result);

$result = Cache::read('test', 'xcache');
$this->assertInstanceOf('stdClass', $result);
$this->assertEquals('an object', $result->value);

Cache::delete('test', 'xcache');
}

Expand Down

0 comments on commit 07bf626

Please sign in to comment.