Skip to content

Instantly share code, notes, and snippets.

@jenkoian
Last active December 11, 2015 22:18
Show Gist options
  • Save jenkoian/4668261 to your computer and use it in GitHub Desktop.
Save jenkoian/4668261 to your computer and use it in GitHub Desktop.
An interface used to implement caching on a controller
<?php
namespace Acme\DemoBundle\Controller;
/**
* Any controller that implements this interface will be eligible for caching. This works by an event
* listener that will look to see if the controller implements this interface and if it does, will call its
* getLastModifiedDate() method to check if the content has been modified or not. If not,
* then it will tell the controller to simply return the 304 response.
*
*/
interface Cacheable
{
/**
* @return boolean Based on the last modified date determine whether the response has changed or not
*/
public function isNotModified(\DateTime $lastModified);
/**
* Work out the last modified date for our caching strategy
* @return \DateTime
*/
public function getLastModifiedDate();
/**
* @return Response The last modified response
*/
public function getLastModifiedResponse();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment