コード例 #1
0
<?php

// Cache data for 2 days
$frontCache = new Phalcon\Cache\Frontend\Base64(array("lifetime" => 172800));
//Create a MongoDB cache
$cache = new Phalcon\Cache\Backend\Mongo($frontCache, array('server' => "mongodb://localhost", 'db' => 'caches', 'collection' => 'images'));
//Cache arbitrary data
$cache->save('my-data', file_get_contents('some-image.jpg'));
//Get data
$data = $cache->get('my-data');
コード例 #2
0
ファイル: CacheTest.php プロジェクト: phalcon/cphalcon
 public function testCacheMongoFlush()
 {
     // Mongo
     list($ready, $collection) = $this->_prepareMongo();
     if (!$ready) {
         return false;
     }
     $frontCache = new Phalcon\Cache\Frontend\Data(array('lifetime' => 10));
     $cache = new Phalcon\Cache\Backend\Mongo($frontCache, array('mongo' => $ready, 'db' => 'phalcon_test', 'collection' => 'caches'));
     $cache->save('data', "1");
     $cache->save('data2', "2");
     $this->assertTrue($cache->flush());
     $this->assertFalse($cache->exists('data'));
     $this->assertFalse($cache->exists('data2'));
 }
コード例 #3
0
<?php

// Cache the files for 2 days using a Base64 frontend
$frontCache = new Phalcon\Cache\Frontend\Base64(array("lifetime" => 172800));
//Create a MongoDB cache
$cache = new Phalcon\Cache\Backend\Mongo($frontCache, array('server' => "mongodb://localhost", 'db' => 'caches', 'collection' => 'images'));
// Try to get cached image
$cacheKey = 'some-image.jpg.cache';
$image = $cache->get($cacheKey);
if ($image === null) {
    // Store the image in the cache
    $cache->save($cacheKey, file_get_contents('tmp-dir/some-image.jpg'));
}
header('Content-Type: image/jpeg');
echo $image;
コード例 #4
0
ファイル: CacheTest.php プロジェクト: racklin/cphalcon
 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'));
 }
コード例 #5
0
ファイル: CacheTest.php プロジェクト: boedy/cphalcon
 public function testCacheMongoFlush()
 {
     $frontCache = new Phalcon\Cache\Frontend\Data(array('lifetime' => 10));
     // Mongo
     $ready = $this->_prepareMongo();
     if (!$ready) {
         return false;
     }
     $mongo = new MongoClient();
     $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'));
     $cache->save('data', "1");
     $cache->save('data2', "2");
     $this->assertTrue($cache->flush());
     $this->assertFalse($cache->exists('data'));
     $this->assertFalse($cache->exists('data2'));
 }