示例#1
0
 /**
  * @param ItemUpdateEvent $event
  */
 public function onStructureItemUpdate(ItemUpdateEvent $event)
 {
     $structureItem = $event->getStructureItem();
     $menuItems = $this->entityManager->getRepository('OctavaMenuBundle:Menu')->getByStructureId($structureItem->getId());
     $this->update($menuItems);
     $this->menuCache->deleteAll();
 }
示例#2
0
 public function onError(ErrorEvent $event)
 {
     //If an error occurs see if data can be served from cache
     $request = $event->getRequest();
     if ($response = $this->cache->fetch($request->__toString())) {
         $event->intercept($response);
     }
 }
示例#3
0
 protected function createFileDriver($name)
 {
     $namespace = $this->config->getRequired("neptune.cache.{$name}.namespace");
     $dir = $this->config->get("neptune.cache.{$name}.dir", sys_get_temp_dir());
     if (substr($dir, 0, 1) !== '/') {
         $dir = $this->neptune->getRootDirectory() . $dir;
     }
     $driver = new FilesystemCache($dir);
     $driver->setNamespace($namespace);
     return $driver;
 }
 public function tearDown()
 {
     $dir = $this->driver->getDirectory();
     $ext = $this->driver->getExtension();
     $iterator = new \RecursiveDirectoryIterator($dir);
     foreach (new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::CHILD_FIRST) as $file) {
         if ($file->isFile()) {
             @unlink($file->getRealPath());
         } else {
             @rmdir($file->getRealPath());
         }
     }
 }
示例#5
0
 public function loadStatsAjaxAction()
 {
     if (null !== ($response = $this->checkAuth(self::RESOURCE_CODE, array(), AccessManager::VIEW))) {
         return $response;
     }
     $cacheExpire = ConfigQuery::getAdminCacheHomeStatsTTL();
     $cacheContent = false;
     $month = (int) $this->getRequest()->query->get('month', date('m'));
     $year = (int) $this->getRequest()->query->get('year', date('Y'));
     if ($cacheExpire) {
         $context = "_" . $month . "_" . $year;
         $cacheKey = self::STATS_CACHE_KEY . $context;
         $cacheDriver = new FilesystemCache($this->getCacheDir());
         if (!$this->getRequest()->query->get('flush', "0")) {
             $cacheContent = $cacheDriver->fetch($cacheKey);
         } else {
             $cacheDriver->delete($cacheKey);
         }
     }
     if ($cacheContent === false) {
         $data = new \stdClass();
         $data->title = $this->getTranslator()->trans("Stats on %month/%year", ['%month' => $month, '%year' => $year]);
         /* sales */
         $saleSeries = new \stdClass();
         $saleSeries->color = self::testHexColor('sales_color', '#adadad');
         $saleSeries->data = OrderQuery::getMonthlySaleStats($month, $year);
         /* new customers */
         $newCustomerSeries = new \stdClass();
         $newCustomerSeries->color = self::testHexColor('customers_color', '#f39922');
         $newCustomerSeries->data = CustomerQuery::getMonthlyNewCustomersStats($month, $year);
         /* orders */
         $orderSeries = new \stdClass();
         $orderSeries->color = self::testHexColor('orders_color', '#5cb85c');
         $orderSeries->data = OrderQuery::getMonthlyOrdersStats($month, $year);
         /* first order */
         $firstOrderSeries = new \stdClass();
         $firstOrderSeries->color = self::testHexColor('first_orders_color', '#5bc0de');
         $firstOrderSeries->data = OrderQuery::getFirstOrdersStats($month, $year);
         /* cancelled orders */
         $cancelledOrderSeries = new \stdClass();
         $cancelledOrderSeries->color = self::testHexColor('cancelled_orders_color', '#d9534f');
         $cancelledOrderSeries->data = OrderQuery::getMonthlyOrdersStats($month, $year, array(5));
         $data->series = array($saleSeries, $newCustomerSeries, $orderSeries, $firstOrderSeries, $cancelledOrderSeries);
         $cacheContent = json_encode($data);
         if ($cacheExpire) {
             $cacheDriver->save($cacheKey, $cacheContent, $cacheExpire);
         }
     }
     return $this->jsonResponse($cacheContent);
 }
 /**
  * Check if cached sitemap can be used or generate a new one and cache it
  *
  * @param $cacheKey
  * @param $cacheDirName
  * @return Response
  */
 public function generateSitemap($cacheKey, $cacheDirName)
 {
     // Get and check locale
     $locale = $this->getSession()->getLang()->getLocale();
     if ("" !== $locale) {
         if (!$this->checkLang($locale)) {
             $this->pageNotFound();
         }
     }
     // Get sitemap cache information
     $sitemapContent = false;
     $cacheDir = $this->getCacheDir($cacheDirName);
     $cacheKey .= $locale;
     $cacheExpire = intval(ConfigQuery::read("sitemap_ttl", '7200')) ?: 7200;
     $cacheDriver = new FilesystemCache($cacheDir);
     // Check if sitemap has to be deleted
     if (!($this->checkAdmin() && "" !== $this->getRequest()->query->get("flush", ""))) {
         // Get cached sitemap
         $sitemapContent = $cacheDriver->fetch($cacheKey);
     } else {
         $cacheDriver->delete($cacheKey);
     }
     // If not in cache, generate and cache it
     if (false === $sitemapContent) {
         // Check if we generate the standard sitemap or the sitemap image
         switch ($cacheDirName) {
             // Image
             case self::SITEMAP_IMAGE_CACHE_DIR:
                 $sitemap = $this->hydrateSitemapImage($locale);
                 break;
                 // Standard
             // Standard
             case self::SITEMAP_CACHE_DIR:
             default:
                 $sitemap = $this->hydrateSitemap($locale);
                 break;
         }
         $sitemapContent = implode("\n", $sitemap);
         // Save cache
         $cacheDriver->save($cacheKey, $sitemapContent, $cacheExpire);
     }
     // Render
     $response = new Response();
     $response->setContent($sitemapContent);
     $response->headers->set('Content-Type', 'application/xml');
     return $response;
 }
示例#7
0
文件: Cache.php 项目: zomars/bolt
 /**
  * Set up the object. Initialize the proper folder for storing the files.
  *
  * @param string            $cacheDir
  * @param Silex\Application $app
  *
  * @throws \Exception
  */
 public function __construct($cacheDir, Silex\Application $app)
 {
     $this->app = $app;
     try {
         parent::__construct($cacheDir, $this->extension);
     } catch (\Exception $e) {
         $app['logger.system']->critical($e->getMessage(), ['event' => 'exception', 'exception' => $e]);
         throw $e;
     }
 }
示例#8
0
 /**
  * Clear the cache. Both the doctrine FilesystemCache, as well as twig and thumbnail temp files.
  *
  * @see clearCacheHelper
  *
  */
 public function clearCache()
 {
     $result = array('successfiles' => 0, 'failedfiles' => 0, 'failed' => array(), 'successfolders' => 0, 'failedfolders' => 0, 'log' => '');
     // Clear Doctrine's folder..
     parent::flushAll();
     // Clear our own cache folder..
     $this->clearCacheHelper($this->getDirectory(), '', $result);
     // Clear the thumbs folder..
     $path = dirname(dirname(dirname(__DIR__))) . "/thumbs";
     $this->clearCacheHelper($path, '', $result);
     return $result;
 }
示例#9
0
 /**
  * Clear the cache. Both the doctrine FilesystemCache, as well as twig and thumbnail temp files.
  *
  * @return bool
  */
 protected function doFlush()
 {
     // Clear Doctrine's folder.
     $result = parent::doFlush();
     if ($this->filesystem instanceof AggregateFilesystemInterface) {
         // Clear our own cache folder.
         $this->flushDirectory($this->filesystem->getFilesystem('cache')->getDir('/'));
         // Clear the thumbs folder.
         $this->flushDirectory($this->filesystem->getFilesystem('web')->getDir('/thumbs'));
     }
     return $result;
 }
示例#10
0
 /**
  * @return Response
  */
 public function generateAction()
 {
     /** @var Request $request */
     $request = $this->getRequest();
     // the locale : fr, en,
     $lang = $request->query->get("lang", "");
     if ("" !== $lang) {
         if (!$this->checkLang($lang)) {
             $this->pageNotFound();
         }
     }
     // specific content : product, category, cms
     $context = $request->query->get("context", "");
     if (!in_array($context, array("", "catalog", "content"))) {
         $this->pageNotFound();
     }
     $flush = $request->query->get("flush", "");
     // check if sitemap already in cache
     $cacheContent = false;
     $cacheDir = $this->getCacheDir();
     $cacheKey = self::SITEMAP_CACHE_KEY . $lang . $context;
     $cacheExpire = intval(ConfigQuery::read("sitemap_ttl", '7200')) ?: 7200;
     $cacheDriver = new FilesystemCache($cacheDir);
     if (!($this->checkAdmin() && "" !== $flush)) {
         $cacheContent = $cacheDriver->fetch($cacheKey);
     } else {
         $cacheDriver->delete($cacheKey);
     }
     // if not in cache
     if (false === $cacheContent) {
         // render the view
         $cacheContent = $this->renderRaw("sitemap", array("_lang_" => $lang, "_context_" => $context));
         // save cache
         $cacheDriver->save($cacheKey, $cacheContent, $cacheExpire);
     }
     $response = new Response();
     $response->setContent($cacheContent);
     $response->headers->set('Content-Type', 'application/xml');
     return $response;
 }
示例#11
0
 /**
  * Clear the cache. Both the doctrine FilesystemCache, as well as twig and thumbnail temp files.
  *
  * @return array
  */
 public function doFlush()
 {
     $result = ['successfiles' => 0, 'failedfiles' => 0, 'failed' => [], 'successfolders' => 0, 'failedfolders' => 0, 'log' => ''];
     // Clear Doctrine's folder.
     parent::doFlush();
     if ($this->filesystem instanceof AggregateFilesystemInterface) {
         // Clear our own cache folder.
         $this->flushFilesystemCache($this->filesystem->getFilesystem('cache'), $result);
         // Clear the thumbs folder.
         $this->flushFilesystemCache($this->filesystem->getFilesystem('thumbs'), $result);
     }
     return $result;
 }
示例#12
0
文件: Cache.php 项目: nectd/nectd-web
 /**
  * Set up the object. Initialize the proper folder for storing the files.
  *
  * @param string      $cacheDir
  * @param Application $app
  *
  * @throws \Exception
  */
 public function __construct($cacheDir, Application $app)
 {
     $this->app = $app;
     try {
         parent::__construct($cacheDir, $this->extension);
         // If the Bolt version has changed, flush our cache
         if (!$this->checkCacheVersion()) {
             $this->clearCache();
         }
     } catch (\Exception $e) {
         $app['logger.system']->critical($e->getMessage(), ['event' => 'exception', 'exception' => $e]);
         throw $e;
     }
 }
 public function testFlushAllWithNoExtension()
 {
     $cache = new FilesystemCache($this->directory, '');
     $this->assertTrue($cache->save('key1', 1));
     $this->assertTrue($cache->save('key2', 2));
     $this->assertTrue($cache->flushAll());
     $this->assertFalse($cache->contains('key1'));
     $this->assertFalse($cache->contains('key2'));
 }
示例#14
0
 /**
  * Retorna a lista de todos as empresas cadastradas na Anvisa.
  *
  * @return array
  */
 public static function listarEmpresas()
 {
     $cacheDriver = new FilesystemCache(sys_get_temp_dir());
     $cacheDriver->setNamespace('hevertonfreitas_bulario_');
     $result = $cacheDriver->fetch('lista_empresas');
     if (empty($result)) {
         $listaEmpresas = file_get_contents('http://www.anvisa.gov.br/datavisa/fila_bula/funcoes/ajax.asp?opcao=getsuggestion&ptipo=2');
         $result = json_decode(utf8_encode($listaEmpresas));
         $cacheDriver->save('lista_empresas', $result);
     }
     return $result;
 }
示例#15
0
 /**
  * @param string $key
  * @param mixed  $item
  *
  * @return bool
  */
 public function save($key, $item, $lifetime = 0)
 {
     return parent::save($key, $item, $lifetime);
 }
示例#16
0
 public function __construct()
 {
     return parent::__construct(sys_get_temp_dir() . DIRECTORY_SEPARATOR . "sonos");
 }
示例#17
0
        $router->add($routeName, $route['pattern'])->addValues(['controller' => $route['controller']]);
    }
    return $router;
}), LoggerInterface::class => factory(function (ContainerInterface $c) {
    $logger = new Logger('main');
    $file = $c->get('directory.logs') . '/app.log';
    $logger->pushHandler(new StreamHandler($file, Logger::WARNING));
    return $logger;
}), Poser::class => object()->constructor(link(SvgFlatRender::class)), Twig_Environment::class => factory(function (ContainerInterface $c) {
    $loader = new Twig_Loader_Filesystem(__DIR__ . '/../../src/Maintained/Application/View');
    $twig = new Twig_Environment($loader);
    $twig->addExtension($c->get(TwigExtension::class));
    $twig->addExtension($c->get(PiwikTwigExtension::class));
    return $twig;
}), PiwikTwigExtension::class => object()->constructor(link('piwik.host'), link('piwik.site_id'), link('piwik.enabled')), Cache::class => factory(function (ContainerInterface $c) {
    $cache = new FilesystemCache($c->get('directory.cache') . '/app');
    $cache->setNamespace('Maintained');
    return $cache;
}), 'storage.repositories' => factory(function (ContainerInterface $c) {
    $backend = new StorageWithTransformers(new FileStorage($c->get('directory.data') . '/repositories.json'));
    $backend->addTransformer(new JsonEncoder(true));
    $storage = new MapWithTransformers(new MapAdapter($backend));
    $storage->addTransformer(new ObjectArrayMapper(Repository::class));
    return $storage;
}), 'storage.statistics' => factory(function (ContainerInterface $c) {
    $storage = new MapWithTransformers(new MultipleFileStorage($c->get('directory.data') . '/statistics'));
    $storage->addTransformer(new PhpSerializeEncoder());
    return $storage;
}), Client::class => factory(function (ContainerInterface $c) {
    $cacheDirectory = $c->get('directory.cache') . '/github';
    $client = new Client(new CachedHttpClient(['cache_dir' => $cacheDirectory]));
示例#18
0
 public function __construct()
 {
     parent::__construct($this->path);
 }
示例#19
0
 /**
  * render the RSS feed
  *
  * @param $context string   The context of the feed : catalog, content. default: catalog
  * @param $lang string      The lang of the feed : fr_FR, en_US, ... default: default language of the site
  * @param $id string        The id of the parent element. The id of the main parent category for catalog context.
  *                          The id of the content folder for content context
  * @return Response
  * @throws \RuntimeException
  */
 public function generateAction($context, $lang, $id)
 {
     /** @var Request $request */
     $request = $this->getRequest();
     // context
     if ("" === $context) {
         $context = "catalog";
     } else {
         if (!in_array($context, array("catalog", "content", "brand"))) {
             $this->pageNotFound();
         }
     }
     // the locale : fr_FR, en_US,
     if ("" !== $lang) {
         if (!$this->checkLang($lang)) {
             $this->pageNotFound();
         }
     } else {
         try {
             $lang = Lang::getDefaultLanguage();
             $lang = $lang->getLocale();
         } catch (\RuntimeException $ex) {
             // @todo generate error page
             throw new \RuntimeException("No default language is defined. Please define one.");
         }
     }
     if (null === ($lang = LangQuery::create()->findOneByLocale($lang))) {
         $this->pageNotFound();
     }
     $lang = $lang->getId();
     // check if element exists and is visible
     if ("" !== $id) {
         if (false === $this->checkId($context, $id)) {
             $this->pageNotFound();
         }
     }
     $flush = $request->query->get("flush", "");
     // check if feed already in cache
     $cacheContent = false;
     $cacheDir = $this->getCacheDir();
     $cacheKey = self::FEED_CACHE_KEY . $lang . $context . $id;
     $cacheExpire = intval(ConfigQuery::read("feed_ttl", '7200')) ?: 7200;
     $cacheDriver = new FilesystemCache($cacheDir);
     if (!($this->checkAdmin() && "" !== $flush)) {
         $cacheContent = $cacheDriver->fetch($cacheKey);
     } else {
         $cacheDriver->delete($cacheKey);
     }
     // if not in cache
     if (false === $cacheContent) {
         // render the view
         $cacheContent = $this->renderRaw("feed", array("_context_" => $context, "_lang_" => $lang, "_id_" => $id));
         // save cache
         $cacheDriver->save($cacheKey, $cacheContent, $cacheExpire);
     }
     $response = new Response();
     $response->setContent($cacheContent);
     $response->headers->set('Content-Type', 'application/rss+xml');
     return $response;
 }
    $logger->pushProcessor(new Monolog\Processor\UidProcessor());
    $logger->pushHandler(new Monolog\Handler\StreamHandler($settings['path'], Monolog\Logger::DEBUG));
    return $logger;
};
// Twig views
$container['view'] = function ($container) {
    $settings = $container->get('settings')['view'];
    $view = new \Slim\Views\Twig($settings['templates'], ['cache' => $settings['cache'], 'debug' => true]);
    $view->addExtension(new \Slim\Views\TwigExtension($container['router'], \nanotwi\Middleware\ProxiedHttpsSupport::getRealUri($container['request'])));
    $view->addExtension(new nanotwi\Views\TwigExtensionAutologinPath($container));
    return $view;
};
// Twig views
$container['cache'] = function ($container) {
    $settings = $container->get('settings')['cache'];
    $cache = new FilesystemCache($settings['path']);
    $cache->setNamespace('twitter_');
    return $cache;
};
// High-level Twitter API
$container['nanoTwitter'] = function ($container) {
    $settings = $container->get('settings')['twitter'];
    $cache = $container->get('cache');
    return new \nanotwi\NanoTwitter($settings, $cache);
};
// Twitter OAuth
$container['oAuthFlow'] = function ($container) {
    $settings = $container->get('settings')['twitter'];
    return new \nanotwi\OAuthFlow($settings['consumerKey'], $settings['consumerSecret']);
};
// Auto-login link
示例#21
0
 private function increaseHitCount()
 {
     $this->hitsCount++;
     $this->cache->save('hitsCount', $this->hitsCount);
 }
 /**
  * @return CacheInterface
  */
 protected function createDefinitionCache($config)
 {
     /** @var CacheInterface $cacheDriver */
     $cacheDriver = null;
     if ('production' == $this->env) {
         $cacheOptions = $config->options;
         switch ($config->type) {
             case 'redis':
                 $redis = new \Redis();
                 $redis->connect($cacheOptions->host, $cacheOptions->port);
                 /** @var RedisCache $cacheDriver */
                 $cacheDriver = new RedisCache();
                 $cacheDriver->setRedis($redis);
                 break;
             case 'memcached':
                 $memcached = new \Memcached();
                 $memcached->addServer($cacheOptions->host, $cacheOptions->port);
                 /** @var MemcachedCache $cacheDriver */
                 $cacheDriver = new MemcachedCache();
                 $cacheDriver->setMemcached($memcached);
                 break;
             case 'apcu':
                 $cacheDriver = new ApcuCache();
                 break;
             default:
                 $cacheDriver = new FilesystemCache(PIMCORE_CACHE_DIRECTORY);
         }
         $cacheDriver->setNamespace($config->namespace);
     }
     return $cacheDriver ? $cacheDriver : new ArrayCache();
 }
 /**
  **
  * Puts data into the cache.
  *
  * @param string $id       The cache id.
  * @param string $data     The cache entry/data.
  * @param int    $lifeTime The lifetime. If != 0, sets a specific lifetime for this
  *                           cache entry (0 => infinite lifeTime).
  *
  * @return bool TRUE if the entry was successfully stored in the cache, FALSE otherwise.
  */
 protected function doSave($id, $data, $lifeTime = 0)
 {
     $e = $this->getStopwatchEvent(__FUNCTION__);
     $result = parent::doSave($id, $data, $lifeTime);
     if ($e) {
         $e->stop();
     }
     return $result;
 }
 /**
  * Fetches an expression from the cache.
  *
  * @param string $key The cache key
  *
  * @return ParsedExpression|null
  */
 public function fetch($key)
 {
     $parsedExpression = $this->fileSystemCache->fetch($key);
     return $parsedExpression ? $parsedExpression : null;
 }