public function testMongoDecrement() { list($ready, $collection) = $this->_prepareMongo(); if (!$ready) { return false; } $frontCache = new Phalcon\Cache\Frontend\Data(array('lifetime' => 200)); $cache = new Phalcon\Cache\Backend\Mongo($frontCache, array('mongo' => $ready, 'db' => 'phalcon_test', 'collection' => 'caches')); $cache->delete('foo'); $cache->save('foo', 100); $this->assertEquals(99, $cache->decrement('foo')); $this->assertEquals(89, $cache->decrement('foo', 10)); $this->assertEquals(89, $cache->get('foo')); $this->assertEquals(1, $cache->decrement('foo', 88)); }
public function _testDataMongoCache() { $ready = $this->_prepareMongo(); if (!$ready) { return false; } //remove existing $mongo = new Mongo(); $database = $mongo->phalcon_test; $collection = $database->caches; $collection->remove(); $frontCache = new Phalcon\Cache\Frontend\Data(); $cache = new Phalcon\Cache\Backend\Mongo($frontCache, array('mongo' => $mongo, 'db' => 'phalcon_test', 'collection' => 'caches')); $data = array(1, 2, 3, 4, 5); $cache->save('test-data', $data); $cachedContent = $cache->get('test-data'); $this->assertEquals($cachedContent, $data); $cache->save('test-data', "sure, nothing interesting"); $cachedContent = $cache->get('test-data'); $this->assertEquals($cachedContent, "sure, nothing interesting"); //Exists $this->assertTrue($cache->exists('test-data')); $this->assertTrue($cache->delete('test-data')); }