3 namespace Friendica\Test\Util;
5 use Friendica\Core\Cache\Duration;
7 trait DbaCacheMockTrait
14 public function __construct()
18 protected function mockDelete($key, $return = true, $times = null)
20 $this->mockDBADelete('cache', ['k' => $key], $return, $times);
23 protected function mockGet($key, $return = null, $time = null, $times = null)
29 $value = @serialize($return);
31 $this->mockSelectFirst('cache', ['v'], ['`k` = ? AND (`expires` >= ? OR `expires` = -1)', $key, $time], ['v' => $value], $times);
32 $this->mockIsResult(['v' => $value], isset($return), $times);
35 protected function mockSet($key, $value, $ttl = Duration::FIVE_MINUTES, $time = null, $return = true, $times = null)
42 $this->mockUtc('now + ' . $ttl . 'seconds', $time + $ttl, $times);
44 'v' => serialize($value),
45 'expires' => $time + $ttl,
50 'v' => serialize($value),
56 $this->mockDBAUpdate('cache', $fields, ['k' => $key], true, $return, $times);
59 protected function mockClear($outdated = true, $return = true, $times = null)
62 $this->mockDBADelete('cache', ['`expires` < NOW()'], $return, $times);
64 $this->mockDBADelete('cache', ['`k` IS NOT NULL '], $return, $times);
68 protected function mockGetAllKeys($prefix = null, $return = [], $time = null, $times = null)
75 $where = ['`expires` >= ?', $time];
77 $where = ['`expires` >= ? AND `k` LIKE CONCAT(?, \'%\')', $time, $prefix];
80 $this->mockSelect('cache', ['k'], $where, $return, $times);
81 $this->mockFetchLoop($return, $times);
82 $this->mockDbaClose(true, $times);