Debian Codegraph @

includes/ResourceLoader/dependencystore/DependencyStore.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 namespace Wikimedia\DependencyStore;
22
23 /**
24 * Track per-module dependency file paths that are expensive to mass compute
25 *
26 * @internal For use by ResourceLoader\Module only
27 */
28 abstract class DependencyStore {
29
30 protected const KEY_PATHS = 'paths';
31 protected const KEY_AS_OF = 'asOf';
32
33 /**
34 * @param string[] $paths List of dependency paths
35 * @param int|null $asOf UNIX timestamp or null
36 * @return array
37 */
38 public function newEntityDependencies( array $paths = [], $asOf = null ) {
39 return [ self::KEY_PATHS => $paths, self::KEY_AS_OF => $asOf ];
40 }
41
42 /**
43 * Get the currently tracked dependencies for an entity
44 *
45 * The "paths" field contains a sorted list of unique paths
46 *
47 * The "asOf" field reflects the last-modified timestamp of the dependency data itself.
48 * It will be null if there is no tracking data available. Note that if empty path lists
49 * are never stored (as an optimisation) then it will not be possible to discern whether
50 * the result is up-to-date.
51 *
52 * @param string $type Entity type
53 * @param string $entity Entity name
54 * @return array Map of (paths: paths, asOf: UNIX timestamp or null)
55 */
56 final public function retrieve( $type, $entity ) {
57 return $this->retrieveMulti( $type, [ $entity ] )[$entity];
58 }
59
60 /**
61 * Get the currently tracked dependencies for a set of entities
62 *
63 * @see KeyValueDependencyStore::retrieve()
64 * @param string $type Entity type
65 * @param string[] $entities Entity names
66 * @return array[] Map of (entity => (paths: paths, asOf: UNIX timestamp or null))
67 */
68 abstract public function retrieveMulti( $type, array $entities );
69
70 /**
71 * Set the currently tracked dependencies for an entity
72 *
73 * @param string $type Entity type
74 * @param string $entity Entity name
75 * @param array $data Map of (paths: paths, asOf: UNIX timestamp or null)
76 * @param int $ttl New time-to-live in seconds
77 */
78 final public function store( $type, $entity, array $data, $ttl ) {
79 $this->storeMulti( $type, [ $entity => $data ], $ttl );
80 }
81
82 /**
83 * Set the currently tracked dependencies for a set of entities
84 *
85 * @see KeyValueDependencyStore::store()
86 * @param string $type Entity type
87 * @param array[] $dataByEntity Map of (entity => (paths: paths, asOf: UNIX timestamp or null))
88 * @param int $ttl New time-to-live in seconds
89 *
90 */
91 abstract public function storeMulti( $type, array $dataByEntity, $ttl );
92
93 /**
94 * Delete the currently tracked dependencies for an entity or set of entities
95 *
96 * @param string $type Entity type
97 * @param string|string[] $entities Entity name(s)
98 */
99 abstract public function remove( $type, $entities );
100 }