Browse Source

fix cache selection method

PHP-GTK3
yggverse 5 months ago
parent
commit
5b020095a3
  1. 14
      src/Abstract/Model/Connection.php
  2. 30
      src/Model/Database.php

14
src/Abstract/Model/Connection.php

@ -239,17 +239,9 @@ abstract class Connection implements \Yggverse\Yoda\Interface\Model\Connection
string $request string $request
): ?object ): ?object
{ {
if ($cache = $this->_database->findCache($request)) return $this->_database->getCache(
{ $request
if (empty($cache[0])) );
{
throw new \Exception;
}
return $cache[0];
}
return null;
} }
public function cache( public function cache(

30
src/Model/Database.php

@ -132,35 +132,27 @@ class Database
); );
} }
public function findCache( public function getCache(
string $request = '', string $request = ''
int $start = 0, ): ?object
int $limit = 1000
): array
{ {
$query = $this->_connection->prepare( $query = $this->_connection->prepare(
sprintf( 'SELECT * FROM `cache` WHERE `request` LIKE :request LIMIT 1'
'SELECT * FROM `cache`
WHERE `request` LIKE :request
ORDER BY `id` DESC
LIMIT %d,%d',
$start,
$limit
)
); );
$query->execute( $query->execute(
[ [
':request' => sprintf( ':request' => $request
'%%%s%%',
$request
)
] ]
); );
return $query->fetchAll(); if ($cache = $query->fetch())
} {
return $cache;
}
return null;
}
public function deleteCache( public function deleteCache(
int $id int $id

Loading…
Cancel
Save