PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.8
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.8
1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 0.8.7 0.8.6 All 33 releases
desktop-mode / includes / framework / app / standalone / class-cache.php

class-cache.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.8, at includes/framework/app/standalone/class-cache.php

56 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OpenStation App Framework — standalone Cache adapter.
4 *
5 * In-process only: lives for the request, honours TTLs, forgets
6 * everything when the process ends.
7 *
8 * @package OpenStation
9 */
10
11 namespace OpenStation\App\Standalone;
12
13 use OpenStation\App\Contracts\Cache as CacheContract;
14
15 // Direct access, unless a standalone host is booting on bare PHP.
16 if ( ! defined( 'ABSPATH' ) ) {
17 defined( 'OPENSTATION_STANDALONE' ) || exit;
18 }
19
20 /**
21 * Per-process cache.
22 */
23 final class Cache implements CacheContract {
24
25 /**
26 * `key => array( expires_at|0, value )`.
27 *
28 * @var array<string,array{0:int,1:mixed}>
29 */
30 private $items = array();
31
32 /** {@inheritDoc} */
33 public function get( $key, $fallback = null ) {
34 if ( ! isset( $this->items[ $key ] ) ) {
35 return $fallback;
36 }
37 list( $expires_at, $value ) = $this->items[ $key ];
38 if ( 0 !== $expires_at && $expires_at < time() ) {
39 unset( $this->items[ $key ] );
40 return $fallback;
41 }
42 return $value;
43 }
44
45 /** {@inheritDoc} */
46 public function set( $key, $value, $ttl = 0 ) {
47 $ttl = (int) $ttl;
48 $this->items[ $key ] = array( $ttl > 0 ? time() + $ttl : 0, $value );
49 }
50
51 /** {@inheritDoc} */
52 public function delete( $key ) {
53 unset( $this->items[ $key ] );
54 }
55 }
56