コード例 #1
0
ファイル: complex_stack_test.php プロジェクト: bmdevel/ezc
 protected function setup()
 {
     if (!self::$stackInitialized) {
         if (ezcBaseFeatures::hasExtensionSupport('apc')) {
             $memoryStorage = new ezcCacheStorageApcPlain();
         } else {
             if (ezcBaseFeatures::hasExtensionSupport('memcache')) {
                 $memoryStorage = new ezcCacheStorageMemcachePlain('foo');
             } else {
                 $this->markTestSkipped('APC or Memcached needed to run this test.');
             }
         }
         // Start cleanly
         $memoryStorage->reset();
         $tmpDir = $this->createTempDir(__CLASS__);
         $tmpDirEvalArray = "{$tmpDir}/plain";
         $tmpDirArray = "{$tmpDir}/array";
         mkdir($tmpDirEvalArray);
         mkdir($tmpDirArray);
         $fileStorageEvalArray = new ezcCacheStorageFileEvalArray($tmpDirEvalArray);
         $fileStorageArray = new ezcCacheStorageFileArray($tmpDirArray);
         ezcCacheStackTestConfigurator::reset();
         ezcCacheStackTestConfigurator::$storages = array(new ezcCacheStackStorageConfiguration('eval_array_storage', $fileStorageEvalArray, 10, 0.8), new ezcCacheStackStorageConfiguration('array_storage', $fileStorageArray, 8, 0.5), new ezcCacheStackStorageConfiguration('memory_storage', $memoryStorage, 5, 0.5));
         ezcCacheStackTestConfigurator::$metaStorage = $fileStorageArray;
         ezcCacheManager::createCache(__CLASS__, null, 'ezcCacheStack', new ezcCacheStackOptions(array('configurator' => 'ezcCacheStackTestConfigurator', 'replacementStrategy' => 'ezcCacheStackLfuReplacementStrategy')));
         self::$stackInitialized = true;
     }
     $this->testDataArray = array(array('id_1', 'id_1_content', array('lang' => 'en', 'area' => 'news')), array('id_2', 'id_2_content', array('lang' => 'en', 'area' => 'news')), array('id_3', 'id_3_content', array('lang' => 'de', 'area' => 'news')), array('id_4', 'id_4_content', array('lang' => 'no', 'area' => 'news')), array('id_5', 'id_5_content', array('lang' => 'de', 'area' => 'news')));
 }
コード例 #2
0
    /**
     * Extract REST routes from APC cache.
     * Cache is generated if needed
     * @return array The route objects
     */
    protected function getCachedRoutes()
    {
        $ttl = (int)eZINI::instance( 'rest.ini' )->variable( 'CacheSettings', 'RouteApcCacheTTL' );

        if( self::$isRouteCacheCreated === false )
        {
            $options = array( 'ttl' => $ttl );
            ezcCacheManager::createCache( self::ROUTE_CACHE_ID, self::ROUTE_CACHE_PATH, 'ezpRestCacheStorageApcCluster', $options );
            self::$isRouteCacheCreated = true;
        }

        $cache = ezcCacheManager::getCache( self::ROUTE_CACHE_ID );
        $cacheKey = self::ROUTE_CACHE_KEY . '_' . ezpRestPrefixFilterInterface::getApiProviderName();
        if( ( $prefixedRoutes = $cache->restore( $cacheKey ) ) === false )
        {
            try
            {
                $prefixedRoutes = $this->doCreateRoutes();
                $cache->store( $cacheKey, $prefixedRoutes );
            }
            catch( Exception $e )
            {
                // Sometimes APC can miss a write. No big deal, just log it.
                // Cache will be regenerated next time
                ezpRestDebug::getInstance()->log( $e->getMessage(), ezcLog::ERROR );
            }
        }

        return $prefixedRoutes;
    }
コード例 #3
0
ファイル: config.php プロジェクト: bdunogier/tcl
 public static function configureObject($id)
 {
     $options = array('ttl' => 1800);
     switch ($id) {
         case 'scrapers':
             ezcCacheManager::createCache('scrapers', '../cache/scrapers', 'ezcCacheStorageFilePlain', $options);
             break;
     }
 }
コード例 #4
0
ファイル: config.php プロジェクト: rangulicon/mkvmanager
 public static function configureObject($id)
 {
     $options = array('ttl' => 300);
     switch ($id) {
         case 'scrapers':
             ezcCacheManager::createCache('scrapers', ROOT . DIRECTORY_SEPARATOR . ezcConfigurationManager::getInstance()->getSetting('movies', 'ScraperSettings', 'TempPath'), 'ezcCacheStorageFilePlain', $options);
             break;
     }
 }
コード例 #5
0
 public static function configureObject($id)
 {
     $options = array('ttl' => 30);
     switch ($id) {
         case 'simple':
             ezcCacheManager::createCache('simple', '/tmp/cache/plain', 'ezcCacheStorageFilePlain', $options);
             break;
     }
 }
コード例 #6
0
ファイル: test_classes.php プロジェクト: bmdevel/ezc
 static function configureObject($identifier)
 {
     if ($identifier !== false) {
         switch ($identifier) {
             case 'simple':
                 ezcCacheManager::createCache($identifier, self::$tmpDir, 'ezcCacheStorageFilePlain');
                 break;
         }
     }
 }
コード例 #7
0
ファイル: index.php プロジェクト: r3-gis/EcoGIS
 }
 $layergroupHighlight = null;
 if ($table == 'tmp') {
     $enableCache = false;
     $layergroupHighlight = 'g_tmp';
     $idValue = session_id();
 } else {
     $enableCache = true;
     $layergroupHighlight = "g_{$table}";
 }
 $fileId = $idValue . '_' . $fileDimensions;
 // set cache attributes
 $cacheAttributes = array('layer' => $table, 'lang' => $languages[$lang], 'id' => $idValue);
 $cadastreIntersection = false;
 $bufferExtent = false;
 ezcCacheManager::createCache('mappreview', R3_CACHE_DIR . 'mappreview/', 'ezcCacheStorageFilePlain', array('ttl' => 5 * 24 * 60 * 60));
 $cache = ezcCacheManager::getCache('mappreview');
 if (!$enableCache || ($imageContent = $cache->restore($fileId, $cacheAttributes)) === false) {
     list($size, $split) = explode('-', $fileDimensions);
     list($x, $y) = explode('x', $size);
     $size = array((int) $x, (int) $y);
     list($unitDimensions, $format) = explode('.', $split);
     $unitDimensions = explode('x', $unitDimensions);
     try {
         switch ($table) {
             case 'foto':
                 $tableName = 'document_data';
                 break;
             default:
                 $tableName = $table;
                 break;
コード例 #8
0
 /**
  * @group restApplicationCache
  * @group restClusterCache
  * @group restCache
  */
 public function testManageCache()
 {
     $cacheOptions = array('ttl' => 2);
     $cacheID = 'test_id';
     $cacheKey = 'myUniqueCacheKey';
     $cacheLocation = 'myLocation';
     $data = array('foo' => 'bar', 'baz' => 123, 'boolean' => true);
     ezcCacheManager::createCache($cacheID, $cacheLocation, 'ezpRestCacheStorageClusterObject', $cacheOptions);
     $cache = ezcCacheManager::getCache($cacheID);
     $cacheContent = $cache->restore($cacheKey);
     // Should be false as we didn't write anything yet
     self::assertFalse($cacheContent, 'Cache should be empty before generation');
     // Remaining lifetime should be 0 as cache does not exist yet
     self::assertSame(0, $cache->getRemainingLifetime($cacheKey));
     // Store the cache
     $cache->store($cacheID, $data);
     $cacheContent = $cache->restore($cacheKey);
     self::assertSame($data, $cacheContent, 'Invalid cache retrieval !');
     // Now check if it is present in the cluster
     $cacheFullLocation = eZSys::cacheDirectory() . '/rest/' . $cacheLocation;
     $cacheFile = $cacheKey . '-.cache';
     self::assertTrue(eZClusterFileHandler::instance()->fileExists($cacheFullLocation . '/' . $cacheFile), 'REST cache file has not been written in the cluster');
     self::assertSame(1, $cache->countDataItems($cacheKey));
     self::assertGreaterThan(0, $cache->getRemainingLifetime($cacheKey), 'Invalid remaining lifetime for REST cache');
     $cache->delete($cacheKey);
     // Test file deletion
     self::assertFalse(eZClusterFileHandler::instance()->fileExists($cacheFullLocation . '/' . $cacheFile), 'REST cache file has not been deleted from the cluster');
 }
コード例 #9
0
<?php

require_once 'tutorial_autoload.php';
class myCustomConfigurator implements ezcCacheStackConfigurator
{
    public static function configure(ezcCacheStack $stack)
    {
        // ... create your storages here or fetch from manager...
        $stack->pushStorage(new ezcCacheStackStorageConfiguration('file', $fileStorage, 1000000, 0.5));
        $stack->pushStorage(new ezcCacheStackStorageConfiguration('apc', $apcStorage, 1000, 0.3));
    }
}
$stackOptions = array('bubbleUpOnRestore' => true, 'configurator' => 'myCustomConfigurator');
$stack = new ezcCacheStack('stack');
ezcCacheManager::createCache('stack', 'stack', 'ezcCacheStack', $stackOptions);
// ... somewhere else...
$stack = ezcCacheManager::getCache('stack');
コード例 #10
0
 public function testCacheManagerLocationEmpty()
 {
     $options = array('ttl' => 10);
     ezcCacheManager::createCache('memory', null, 'ezcCacheStorageFileApcArray', $options);
     try {
         $storage = ezcCacheManager::getCache('memory');
         $this->fail("Expected exception was not thrown");
     } catch (ezcBaseFilePermissionException $e) {
         $this->assertEquals("The file '/' can not be opened for writing. (Cache location is not a directory.)", $e->getMessage());
     }
 }
コード例 #11
0
 /**
  * Override to add the "requestedResponseGroups" variable for every REST requests
  *
  * @see lib/ezc/MvcTools/src/interfaces/ezcMvcController::createResult()
  */
 public function createResult()
 {
     $debug = ezpRestDebug::getInstance();
     $debug->startTimer('GeneratingRestResult', 'RestController');
     if (!self::$isCacheCreated) {
         ezcCacheManager::createCache(self::CACHE_ID, $this->getCacheLocation(), 'ezpRestCacheStorageClusterObject', array('ttl' => $this->getActionTTL()));
         self::$isCacheCreated = true;
     }
     $cache = ezcCacheManager::getCache(self::CACHE_ID);
     $controllerCacheId = $this->generateCacheId();
     $isCacheEnabled = $this->isCacheEnabled();
     // Try to restore application cache.
     // If expired or not yet available, generate it and store it
     $cache->isCacheEnabled = $isCacheEnabled;
     if (($res = $cache->restore($controllerCacheId)) === false) {
         try {
             $debug->log('Generating cache', ezcLog::DEBUG);
             $debug->switchTimer('GeneratingCache', 'GeneratingRestResult');
             $res = parent::createResult();
             $resGroups = $this->getResponseGroups();
             if (!empty($resGroups)) {
                 $res->variables['requestedResponseGroups'] = $resGroups;
             }
             if ($res instanceof ezpRestMvcResult) {
                 $res->responseGroups = $resGroups;
             }
             if ($isCacheEnabled) {
                 $cache->store($controllerCacheId, $res);
             }
             $debug->stopTimer('GeneratingCache');
         } catch (Exception $e) {
             $debug->log('Exception caught, aborting cache generation', ezcLog::DEBUG);
             if ($isCacheEnabled) {
                 $cache->abortCacheGeneration();
             }
             throw $e;
         }
     }
     // Add debug infos to output if debug is enabled
     $debug->stopTimer('GeneratingRestResult');
     if (ezpRestDebug::isDebugEnabled()) {
         $res->variables['debug'] = $debug->getReport();
     }
     return $res;
 }
コード例 #12
0
}
// Central creation and configuration of the caches
// The ezcCacheManager just stores the configuration right now and
// performs sanity checks. The {@link ezcCacheStorage} instances
// will be created on demand, when you use them for the first time
// Configuration options for a cache {@link ezcCacheStorage}
$options = array('ttl' => 60 * 60 * 24 * 2);
// Create a cache named "content", that resides in /var/cache/content
// The cache instance will use the {@link ezcCacheStorageFileArray} class
// to store the cache data. The time-to-live for cache items is set as
// defined above.
ezcCacheManager::createCache('content', $basePath . '/content', 'ezcCacheStorageFileArray', $options);
// Create another cache, called "template" in /var/cache/templates.
// This cache will use the {@link ezcCacheStorageFilePlain} class to store
// cache data. It has the same TTL as the cache defined above.
ezcCacheManager::createCache('template', $basePath . '/templates', 'ezcCacheStorageFilePlain', $options);
// Somewhere in the application you can access the caches
// Get the instance of the cache called "content"
// Now the instance of {@link ezcCacheStorageFileArray is created and
// returned to be used. Next time you access this cache, the created
// instance will be reused.
$cache = ezcCacheManager::getCache('content');
// Specify any number of attributes to identify the cache item you want
// to store. This attributes can be used later to perform operations
// on a set of cache items, that share a common attribute.
$attributes = array('node' => 2, 'area' => 'admin', 'lang' => 'en-GB');
// This function is not part of the Cache package. You have to define
// unique IDs for your cache items yourself.
$id = getUniqueId();
// Initialize the data variable you want to restore
$data = '';
コード例 #13
0
ファイル: cache.php プロジェクト: SandyS1/presentations
<?php

require 'ezc-setup.php';
@mkdir('/tmp/temp-location');
ezcCacheManager::createCache('identifier', '/tmp/temp-location', 'ezcCacheStorageFileEvalArray', array('ttl' => 30));
$cache = ezcCacheManager::getCache('identifier');
$myId = 'unique_id_1';
if (($data = $cache->restore($myId)) === false) {
    $data = "Plain cache stored on " . date('Y-m-d, H:i:s');
    $cache->store($myId, $data);
}
echo $data;
<?php

require_once 'tutorial_autoload.php';
$optionsPlain = array('ttl' => 30);
$optionsArray = array('ttl' => 45);
ezcCacheManager::createCache('plain', '/tmp/cache/plain', 'ezcCacheStorageFilePlain', $optionsPlain);
ezcCacheManager::createCache('array', '/tmp/cache/array', 'ezcCacheStorageFileArray', $optionsArray);
$myId = 'unique_id_2';
$cache = ezcCacheManager::getCache('plain');
if (($plainData = $cache->restore($myId)) === false) {
    $plainData = "Plain cache stored on " . date('Y-m-d, H:m:s');
    $cache->store($myId, $plainData);
    sleep(2);
}
echo "Plain cache data:\n";
var_dump($plainData);
$cache = ezcCacheManager::getCache('array');
if (($arrayData = $cache->restore($myId)) === false) {
    $arrayData = array($plainData, "Array cache stored on " . date('Y-m-d, H:m:s'), true, 23);
    $cache->store($myId, $arrayData);
}
echo "Array cache data:\n";
var_dump($arrayData);
コード例 #15
0
 public function testCacheManagerLocationEmpty()
 {
     $options = array('ttl' => 10);
     ezcCacheManager::createCache('cache', null, 'ezcCacheStorageApcPlain', $options);
     $storage = ezcCacheManager::getCache('cache');
     $storage->reset();
     $storage->store('key', 'data');
     $this->assertEquals('data', $storage->restore('key'));
 }
コード例 #16
0
 public function testCacheBackendSingleConnection()
 {
     $options = array('host' => 'localhost', 'port' => 11211, 'ttl' => 10);
     ezcCacheManager::createCache('cache-a', null, 'ezcCacheStorageMemcachePlain', $options);
     ezcCacheManager::createCache('cache-b', null, 'ezcCacheStorageMemcachePlain', $options);
     $storageA = ezcCacheManager::getCache('cache-a');
     $storageA->reset();
     $storageB = ezcCacheManager::getCache('cache-b');
     $storageA->reset();
     $backendA = $this->readAttribute($storageA, 'backend');
     $backendB = $this->readAttribute($storageB, 'backend');
     $memcacheA = $this->readAttribute($backendA, 'memcache');
     $memcacheB = $this->readAttribute($backendB, 'memcache');
     $this->assertSame($memcacheA, $memcacheB);
     unset($storageA);
     unset($storageA);
 }
コード例 #17
0
<?php

require_once 'tutorial_autoload.php';
$options = array('ttl' => 30, 'host' => 'localhost', 'port' => 11211);
ezcCacheManager::createCache('memcache', 'memcache', 'ezcCacheStorageMemcachePlain', $options);
$myId = 'unique_id_1';
$mySecondId = 'id_2';
$cache = ezcCacheManager::getCache('memcache');
if (($dataOfFirstItem = $cache->restore($myId)) === false) {
    $dataOfFirstItem = "Plain cache stored on " . date('Y-m-d, H:i:s');
    $cache->store($myId, $dataOfFirstItem);
}
if (($dataOfSecondItem = $cache->restore($mySecondId)) === false) {
    $dataOfSecondItem = "Plain cache 2 stored on " . date('Y-m-d, H:i:s');
    $cache->store($mySecondId, $dataOfSecondItem);
}
var_dump($dataOfFirstItem, $dataOfSecondItem);
コード例 #18
0
ファイル: manager_test.php プロジェクト: zetacomponents/cache
 public function testManagerCreateCache_Failure()
 {
     $id = 0;
     // First try to create cache in invalid location.
     $caughtException = false;
     try {
         $cache = ezcCacheManager::createCache($id, '/fckgw', $this->data[$id]);
         $this->fail('Exception not thrown on invalid location </fckgw>.');
     } catch (ezcBaseFileNotFoundException $e) {
         $this->assertEquals("The cache location file '/fckgw' could not be found. (Does not exist or is no directory.)", $e->getMessage());
     }
     // Second try, allocate a cache succesfully
     $location = $this->createTempDir($this->data[$id]);
     $cache = ezcCacheManager::createCache($id, $location, $this->data[$id]);
     // Use next cache class/location.
     $id++;
     $caughtException = false;
     try {
         // Use current ID with last IDs location
         ezcCacheManager::createCache($id, $location, $this->data[$id]);
     } catch (ezcCacheUsedLocationException $e) {
         $caughtException = true;
     }
     if ($caughtException === false) {
         $this->fail('Exception not thrown on used location <' . $location . '>.');
     }
     $this->removeTempDir($location);
     // Use next cache class/location.
     $id++;
     $caughtException = false;
     $location = $this->createTempDir($this->data[$id]);
     try {
         // Use current ID with non-existant cache class
         ezcCacheManager::createCache($id, $location, 'Test');
     } catch (ezcCacheInvalidStorageClassException $e) {
         $caughtException = true;
     }
     if ($caughtException === false) {
         $this->fail('Wrong exception thrown on invalid storage class <Test>.');
     }
     $this->removeTempDir($location);
 }
コード例 #19
0
<?php

require_once 'tutorial_autoload.php';
$options = array('ttl' => 30);
ezcCacheManager::createCache('simple', '/tmp/cache/plain', 'ezcCacheStorageFilePlain', $options);
$myId = 'unique_id_1';
$mySecondId = 'id_2';
$cache = ezcCacheManager::getCache('simple');
if (($dataOfFirstItem = $cache->restore($myId)) === false) {
    $dataOfFirstItem = "Plain cache stored on " . date('Y-m-d, H:i:s');
    $cache->store($myId, $dataOfFirstItem);
}
if (($dataOfSecondItem = $cache->restore($mySecondId)) === false) {
    $dataOfSecondItem = "Plain cache 2 stored on " . date('Y-m-d, H:i:s');
    $cache->store($mySecondId, $dataOfSecondItem);
}
var_dump($dataOfFirstItem, $dataOfSecondItem);
コード例 #20
0
<?php

require_once 'tutorial_autoload.php';
$options = array('ttl' => 30);
ezcCacheManager::createCache('apc', 'apc', 'ezcCacheStorageApcPlain', $options);
$myId = 'unique_id_1';
$mySecondId = 'id_2';
$cache = ezcCacheManager::getCache('apc');
if (($dataOfFirstItem = $cache->restore($myId)) === false) {
    $dataOfFirstItem = "Plain cache stored on " . date('Y-m-d, H:i:s');
    $cache->store($myId, $dataOfFirstItem);
}
if (($dataOfSecondItem = $cache->restore($mySecondId)) === false) {
    $dataOfSecondItem = "Plain cache 2 stored on " . date('Y-m-d, H:i:s');
    $cache->store($mySecondId, $dataOfSecondItem);
}
var_dump($dataOfFirstItem, $dataOfSecondItem);