Cache.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Swift Mailer Runtime caching base component.
  4. * Please read the LICENSE file
  5. * @author Chris Corbyn <chris@w3style.co.uk>
  6. * @package Swift_Cache
  7. * @license GNU Lesser General Public License
  8. */
  9. require_once dirname(__FILE__) . "/ClassLoader.php";
  10. /**
  11. * The interface for any cache mechanisms to follow
  12. * @package Swift_Cache
  13. * @author Chris Corbyn <chris@w3style.co.uk>
  14. */
  15. abstract class Swift_Cache
  16. {
  17. /**
  18. * Append bytes to the cache buffer identified by $key
  19. * @param string The Cache key
  20. * @param string The bytes to append
  21. */
  22. abstract public function write($key, $data);
  23. /**
  24. * Clear out the buffer for $key
  25. * @param string The cache key
  26. */
  27. abstract public function clear($key);
  28. /**
  29. * Check if there is something in the cache for $key
  30. * @param string The cache key
  31. * @return boolean
  32. */
  33. abstract public function has($key);
  34. /**
  35. * Read bytes from the cached buffer and seek forward in the buffer
  36. * Returns false once no more bytes are left to read
  37. * @param int The number of bytes to read (may be ignored)
  38. * @return string
  39. */
  40. abstract public function read($key, $size=null);
  41. /**
  42. * A factory method to return an output stream object for the relevant location in the cache
  43. * @param string The cache key to fetch the stream for
  44. * @return Swift_Cache_OutputStream
  45. */
  46. public function getOutputStream($key)
  47. {
  48. Swift_ClassLoader::load("Swift_Cache_OutputStream");
  49. $os = new Swift_Cache_OutputStream($this, $key);
  50. return $os;
  51. }
  52. }