Skip to content

Commit

Permalink
[AsseticBundle] added local caching to the controller
Browse files Browse the repository at this point in the history
  • Loading branch information
kriswallsmith authored and fabpot committed Feb 16, 2011
1 parent 42a68d9 commit cd5b603
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Symfony/Bundle/AsseticBundle/Controller/AsseticController.php
Expand Up @@ -11,7 +11,9 @@

namespace Symfony\Bundle\AsseticBundle\Controller;

use Assetic\Asset\AssetCache;
use Assetic\AssetManager;
use Assetic\Cache\CacheInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
Expand All @@ -26,12 +28,14 @@ class AsseticController
protected $request;
protected $response;
protected $am;
protected $cache;

public function __construct(Request $request, Response $response, AssetManager $am)
public function __construct(Request $request, Response $response, AssetManager $am, CacheInterface $cache)
{
$this->request = $request;
$this->response = $response;
$this->am = $am;
$this->cache = $cache;
}

public function render($name)
Expand All @@ -40,7 +44,7 @@ public function render($name)
throw new NotFoundHttpException('Asset Not Found');
}

$asset = $this->am->get($name);
$asset = $this->getAsset($name);

// validate if-modified-since
if (null !== $lastModified = $asset->getLastModified()) {
Expand All @@ -57,4 +61,9 @@ public function render($name)

return $this->response;
}

protected function getAsset($name)
{
return new AssetCache($this->am->get($name), $this->cache);
}
}
Expand Up @@ -7,6 +7,8 @@
<parameters>
<parameter key="assetic.controller.class">Symfony\Bundle\AsseticBundle\Controller\AsseticController</parameter>
<parameter key="assetic.routing_loader.class">Symfony\Bundle\AsseticBundle\Routing\AsseticLoader</parameter>
<parameter key="assetic.cache.class">Assetic\Cache\FilesystemCache</parameter>
<parameter key="assetic.cache_dir">%kernel.cache_dir%/assetic</parameter>
</parameters>

<services>
Expand All @@ -18,6 +20,10 @@
<argument type="service" id="request" />
<argument type="service" id="response" />
<argument type="service" id="assetic.asset_manager" />
<argument type="service" id="assetic.cache" />
</service>
<service id="assetic.cache" class="%assetic.cache.class%" public="false">
<argument>%assetic.cache_dir%</argument>
</service>
</services>
</container>
Expand Up @@ -39,6 +39,7 @@ protected function setUp()
$this->container->register('twig', 'Twig_Environment');
$this->container->setParameter('kernel.debug', false);
$this->container->setParameter('kernel.root_dir', __DIR__);
$this->container->setParameter('kernel.cache_dir', __DIR__);
$this->container->setParameter('kernel.bundles', array());
}

Expand Down

0 comments on commit cd5b603

Please sign in to comment.