Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <nick@popphp.org>
8 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Cache\Adapter;
16
17/**
18 * Cache adapter interface
19 *
20 * @category   Pop
21 * @package    Pop\Cache
22 * @author     Nick Sagona, III <nick@popphp.org>
23 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
24 * @license    https://www.popphp.org/license     New BSD License
25 * @version    5.0.0
26 */
27interface AdapterInterface
28{
29
30    /**
31     * Set the global time-to-live for the cache adapter
32     *
33     * @param  int $ttl
34     * @return AdapterInterface
35     */
36    public function setTtl(int $ttl): AdapterInterface;
37
38    /**
39     * Get the global time-to-live for the cache object
40     *
41     * @return int
42     */
43    public function getTtl(): int;
44
45    /**
46     * Get the time-to-live for an item in cache
47     *
48     * @param  string $id
49     * @param  int    $default
50     * @return int
51     */
52    public function getItemTtl(string $id, int $default = 0): int;
53
54    /**
55     * Save an item to cache
56     *
57     * @param  string $id
58     * @param  mixed  $value
59     * @param  ?int   $ttl
60     * @return AdapterInterface
61     */
62    public function saveItem(string $id, mixed $value, ?int $ttl = null): AdapterInterface;
63
64    /**
65     * Get an item from cache
66     *
67     * @param  string $id
68     * @param  mixed  $default
69     * @return mixed
70     */
71    public function getItem(string $id, mixed $default = false): mixed;
72
73    /**
74     * Determine if the item exist in cache
75     *
76     * @param  string $id
77     * @return bool
78     */
79    public function hasItem(string $id): bool;
80
81    /**
82     * Delete a value in cache
83     *
84     * @param  string $id
85     * @return AdapterInterface
86     */
87    public function deleteItem(string $id): AdapterInterface;
88
89    /**
90     * Clear all stored values from cache
91     *
92     * @return AdapterInterface
93     */
94    public function clear(): AdapterInterface;
95
96    /**
97     * Destroy cache resource
98     *
99     * @return AdapterInterface
100     */
101    public function destroy(): AdapterInterface;
102
103    /**
104     * Atomically increment a counter in cache, creating it at $initial if it doesn't exist
105     *
106     * @param  string $id
107     * @param  int    $amount
108     * @param  int    $initial
109     * @param  ?int   $ttl
110     * @return int
111     */
112    public function incrementItem(string $id, int $amount = 1, int $initial = 0, ?int $ttl = null): int;
113
114    /**
115     * Atomically decrement a counter in cache, creating it at $initial if it doesn't exist
116     *
117     * @param  string $id
118     * @param  int    $amount
119     * @param  int    $initial
120     * @param  ?int   $ttl
121     * @return int
122     */
123    public function decrementItem(string $id, int $amount = 1, int $initial = 0, ?int $ttl = null): int;
124
125}