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