Browse Source

cache Room::_post

main
ghost 10 months ago
parent
commit
997cc8d039
  1. 54
      src/controller/room.php

54
src/controller/room.php

@ -329,6 +329,29 @@ class Room
private function _post(string $namespace, string $key, array $posts = [], ?string $field = null, ?int &$time = 0): ?string private function _post(string $namespace, string $key, array $posts = [], ?string $field = null, ?int &$time = 0): ?string
{ {
// Check for cache
$result = $this->_memory->get(
[
$namespace,
$key,
$field
]
);
$time = $this->_memory->get(
[
$namespace,
$key,
$field,
'time'
]
);
if ($result && $time)
{
return $result;
}
// Check record exists // Check record exists
if (!$record = (array) $this->_kevacoin->kevaGet($namespace, $key)) if (!$record = (array) $this->_kevacoin->kevaGet($namespace, $key))
{ {
@ -463,11 +486,8 @@ class Room
// Return timestamp // Return timestamp
$time = $matches[1]; $time = $matches[1];
// Build final view and send to response // Build final view and save to result
return $result = preg_replace(
// Allow up to 2 line separators
preg_replace(
[ [
'/[\n\r]{1}/', '/[\n\r]{1}/',
'/[\n\r]{3,}/' '/[\n\r]{3,}/'
@ -514,6 +534,30 @@ class Room
) )
) )
); );
// Check for cached results
$this->_memory->set(
[
$namespace,
$key,
$field
],
$result,
time() + 60
);
$this->_memory->set(
[
$namespace,
$key,
$field,
$time
],
$time,
time() + 60
);
return $result;
} }
private function _ago(int $time): string private function _ago(int $time): string

Loading…
Cancel
Save