Cotonti Aik |
|
---|---|
#45833 Alex300: Добрый вечер, как я понял метод Этот метод может быть объявлен по примеру: class CotDB { // Другие свойства и методы класса /** * Execute a SQL query and cache the result * * @param string $query SQL query * @param string $cache_name Cache file name * @param int $ttl Cache TTL in seconds * @return CotDBResult */ public function query_cache($query, $cache_name, $ttl = 600) { // Реализация метода } }
https://www.cotonti.com/system/lib/cotdb.php (The page you are looking for is unavailable for security reason.) Как вариант реализации метода class CotDB { // Другие свойства и методы класса /** * Execute a SQL query and cache the result * * @param string $query SQL query * @param string $cache_name Cache file name * @param int $ttl Cache TTL in seconds * @return CotDBResult */ public function query_cache($query, $cache_name, $ttl = 600) { // Путь к файлу кеша $cache_file = $this->cache_dir . '/' . $cache_name . '.php'; // Если файл кеша существует и не истек срок его жизни, возвращаем результаты из кеша if (file_exists($cache_file) && (time() - filemtime($cache_file) < $ttl)) { return unserialize(file_get_contents($cache_file)); } // Выполняем запрос $result = $this->query($query); // Сохраняем результаты в кеш file_put_contents($cache_file, serialize($result)); // Возвращаем результаты return $result; } } Проверяем есть ли сам файл, не стек ли тайминг файла, если все хорошо берем из кеше если нет то следовательно к БД. https://t.me/cotontiaik - Телега о Cotonti
|
|
This post was edited by Cotonti Aik (2023-01-06 19:19, 1 year ago) |