-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exception fix
- Loading branch information
Showing
38 changed files
with
506 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
|
||
namespace Core\Cache; | ||
|
||
|
||
use Core\Era\Era; | ||
use DateInterval; | ||
|
||
abstract class BaseCache implements CacheInterface | ||
{ | ||
/** | ||
* @param null|int|DateInterval $ttl | ||
* @return int | ||
*/ | ||
protected function ttl($ttl = null): int | ||
{ | ||
if (is_null($ttl)) { | ||
$ttl = 0; | ||
} | ||
|
||
if ($ttl instanceof DateInterval) { | ||
$ttl = Era::dateIntervalTo($ttl, 'second'); | ||
} | ||
|
||
return (int)$ttl; | ||
} | ||
|
||
/** | ||
* @param $ttl | ||
* @return int | ||
* @throws \Exception | ||
*/ | ||
protected function expires($ttl): int | ||
{ | ||
$seconds = $this->ttl($ttl); | ||
$seconds = $seconds ?: 315360000; | ||
return Era::now()->addSecond($seconds)->getTimestamp(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
abstract public function get(string $key, $default = null); | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
abstract public function set(string $key, $value, $ttl = null): bool; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
abstract public function add(string $key, $value, $ttl = null): bool; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
abstract public function getSet(string $key, $ttl = null, $default = null); | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
abstract public function delete(string $key): bool; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
abstract public function clear(): bool; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
abstract public function getMultiple(array $keys): array; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
abstract public function setMultiple(array $items, $ttl = null): bool; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
abstract public function deleteMultiple(array $keys): bool; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
abstract public function has(string $key): bool; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
abstract public function increment(string $key, $value = 1); | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
abstract public function decrement(string $key, $value = 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.