PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.2.7
Yatra – Travel Booking & Tour Operator Software v3.0.2.7
3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 All 83 releases
yatra / app / Repositories / Concerns / CachesQueryResults.php

CachesQueryResults.php in Yatra – Travel Booking & Tour Operator Software 3.0.2.7, at app/Repositories/Concerns/CachesQueryResults.php

40 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Repositories\Concerns;
6
7 use Yatra\Utils\Cache;
8
9 /**
10 * Query-result caching for repository classes (DB reads, external API payloads composed here).
11 * Do not use for WordPress options — call {@see get_option()} directly without wrapping in {@see Cache}.
12 *
13 * Pair reads with invalidation on writes: override {@see \Yatra\Repositories\BaseRepository::afterWrite}
14 * or fire domain hooks that {@see \Yatra\Hooks\CacheHooks} / {@see \Yatra\Utils\Cache} handle.
15 */
16 trait CachesQueryResults
17 {
18 /**
19 * @param callable(): mixed $callback
20 *
21 * @return mixed
22 */
23 protected function cacheQueryResult(string $key, callable $callback, int $duration = 3600)
24 {
25 return Cache::remember($key, $callback, $duration);
26 }
27
28 /**
29 * Lets application services keep orchestration while storing cache keys and TTLs on the repository.
30 *
31 * @param callable(): mixed $callback
32 *
33 * @return mixed
34 */
35 public function withQueryCache(string $key, callable $callback, int $duration = 3600)
36 {
37 return $this->cacheQueryResult($key, $callback, $duration);
38 }
39 }
40