1<?php
2
3declare(strict_types=1);
4/**
5 * SimplePie
6 *
7 * A PHP-Based RSS and Atom Feed Framework.
8 * Takes the hard work out of managing a complete RSS/Atom solution.
9 *
10 * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
11 * All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without modification, are
14 * permitted provided that the following conditions are met:
15 *
16 * 	* Redistributions of source code must retain the above copyright notice, this list of
17 * 	  conditions and the following disclaimer.
18 *
19 * 	* Redistributions in binary form must reproduce the above copyright notice, this list
20 * 	  of conditions and the following disclaimer in the documentation and/or other materials
21 * 	  provided with the distribution.
22 *
23 * 	* Neither the name of the SimplePie Team nor the names of its contributors may be used
24 * 	  to endorse or promote products derived from this software without specific prior
25 * 	  written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
28 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
29 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
30 * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 * @package SimplePie
38 * @copyright 2004-2022 Ryan Parman, Sam Sneddon, Ryan McCue
39 * @author Ryan Parman
40 * @author Sam Sneddon
41 * @author Ryan McCue
42 * @link http://simplepie.org/ SimplePie
43 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
44 */
45
46namespace SimplePie\Cache;
47
48use InvalidArgumentException;
49
50/**
51 * Subset of PSR-16 Cache client for caching data arrays
52 *
53 * Only get(), set() and delete() methods are used,
54 * but not has(), getMultiple(), setMultiple() or deleteMultiple().
55 *
56 * The methods names must be different, but should be compatible to the
57 * methods of \Psr\SimpleCache\CacheInterface.
58 *
59 * @package SimplePie
60 * @subpackage Caching
61 * @internal
62 */
63interface DataCache
64{
65    /**
66     * Fetches a value from the cache.
67     *
68     * Equivalent to \Psr\SimpleCache\CacheInterface::get()
69     * <code>
70     * public function get(string $key, mixed $default = null): mixed;
71     * </code>
72     *
73     * @param string   $key     The unique key of this item in the cache.
74     * @param mixed    $default Default value to return if the key does not exist.
75     *
76     * @return array|mixed The value of the item from the cache, or $default in case of cache miss.
77     *
78     * @throws InvalidArgumentException
79     *   MUST be thrown if the $key string is not a legal value.
80     */
81    public function get_data(string $key, $default = null);
82
83    /**
84     * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.
85     *
86     * Equivalent to \Psr\SimpleCache\CacheInterface::set()
87     * <code>
88     * public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool;
89     * </code>
90     *
91     * @param string   $key   The key of the item to store.
92     * @param array    $value The value of the item to store, must be serializable.
93     * @param null|int $ttl   Optional. The TTL value of this item. If no value is sent and
94     *                                      the driver supports TTL then the library may set a default value
95     *                                      for it or let the driver take care of that.
96     *
97     * @return bool True on success and false on failure.
98     *
99     * @throws InvalidArgumentException
100     *   MUST be thrown if the $key string is not a legal value.
101     */
102    public function set_data(string $key, array $value, ?int $ttl = null): bool;
103
104    /**
105     * Delete an item from the cache by its unique key.
106     *
107     * Equivalent to \Psr\SimpleCache\CacheInterface::delete()
108     * <code>
109     * public function delete(string $key): bool;
110     * </code>
111     *
112     * @param string $key The unique cache key of the item to delete.
113     *
114     * @return bool True if the item was successfully removed. False if there was an error.
115     *
116     * @throws InvalidArgumentException
117     *   MUST be thrown if the $key string is not a legal value.
118     */
119    public function delete_data(string $key): bool;
120}
121