Use ephemeral cache during installation

This commit is contained in:
Dmitriy Simushev 2014-11-07 11:40:36 +00:00
parent 2c9a6830c8
commit 2c0d88c4d5
2 changed files with 23 additions and 7 deletions

View File

@ -27,6 +27,7 @@ use Mibew\Routing\Router;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\FileLocator;
// Prepare router
$file_locator = new FileLocator(array(MIBEW_FS_ROOT)); $file_locator = new FileLocator(array(MIBEW_FS_ROOT));
$router = new Router(new RouteCollectionLoader($file_locator)); $router = new Router(new RouteCollectionLoader($file_locator));
$router->setOption( $router->setOption(
@ -34,7 +35,13 @@ $router->setOption(
RouteCollectionLoader::ROUTES_CORE | RouteCollectionLoader::ROUTES_PLUGINS RouteCollectionLoader::ROUTES_CORE | RouteCollectionLoader::ROUTES_PLUGINS
); );
// Prepare files cache
$cache_driver = new \Stash\Driver\FileSystem();
$cache_driver->setOptions(array('path' => MIBEW_FS_ROOT . '/cache'));
$cache = new \Stash\Pool($cache_driver);
$application = new Application($router, new AuthenticationManager()); $application = new Application($router, new AuthenticationManager());
$application->setCache($cache);
// Process request // Process request
$request = Request::createFromGlobals(); $request = Request::createFromGlobals();

View File

@ -24,6 +24,7 @@ use Mibew\Asset\AssetManager;
use Mibew\Asset\AssetManagerInterface; use Mibew\Asset\AssetManagerInterface;
use Mibew\Authentication\AuthenticationManagerInterface; use Mibew\Authentication\AuthenticationManagerInterface;
use Mibew\Authentication\AuthenticationManagerAwareInterface; use Mibew\Authentication\AuthenticationManagerAwareInterface;
use Mibew\Cache\CacheAwareInterface;
use Mibew\Controller\ControllerResolver; use Mibew\Controller\ControllerResolver;
use Mibew\EventDispatcher\EventDispatcher; use Mibew\EventDispatcher\EventDispatcher;
use Mibew\EventDispatcher\Events; use Mibew\EventDispatcher\Events;
@ -47,7 +48,10 @@ use Symfony\Component\Routing\Exception\ResourceNotFoundException as ResourceNot
/** /**
* Incapsulates whole application * Incapsulates whole application
*/ */
class Application implements RouterAwareInterface, AuthenticationManagerAwareInterface class Application implements
RouterAwareInterface,
AuthenticationManagerAwareInterface,
CacheAwareInterface
{ {
/** /**
* @var RouterInterface|null * @var RouterInterface|null
@ -201,15 +205,20 @@ class Application implements RouterAwareInterface, AuthenticationManagerAwareInt
} }
/** /**
* Returns an instance of Cache Pool related with the application. * {@inheritdoc}
*
* @return PoolInterface
*/ */
protected function getCache() public function setCache(PoolInterface $cache)
{
$this->cache = $cache;
}
/**
* {@inheritdoc}
*/
public function getCache()
{ {
if (is_null($this->cache)) { if (is_null($this->cache)) {
$driver = new \Stash\Driver\FileSystem(); $driver = new \Stash\Driver\Ephemeral();
$driver->setOptions(array('path' => MIBEW_FS_ROOT . '/cache'));
$this->cache = new \Stash\Pool($driver); $this->cache = new \Stash\Pool($driver);
} }