mirror of
https://github.com/manualdousuario/marreta.git
synced 2025-09-01 18:20:22 +00:00
adicionado modo de debug que não cria cache
This commit is contained in:
parent
ed9c05d515
commit
b901357081
3 changed files with 22 additions and 0 deletions
|
@ -14,3 +14,7 @@ SITE_URL=https://localhost
|
|||
# Lista de servidores DNS para resolução de domínios
|
||||
# Recomendado: AdGuard DNS (94.140.14.14, 94.140.15.15)
|
||||
DNS_SERVERS='94.140.14.14,94.140.15.15'
|
||||
|
||||
# Modo de debug (true/false)
|
||||
# Quando ativo, desativa o cache do sistema
|
||||
DEBUG=false
|
||||
|
|
|
@ -26,6 +26,7 @@ define('SITE_URL', isset($_ENV['SITE_URL']) ? $_ENV['SITE_URL'] : 'https://' . $
|
|||
define('MAX_ATTEMPTS', 3); // Número máximo de tentativas para acessar uma URL
|
||||
define('DNS_SERVERS', isset($_ENV['DNS_SERVERS']) ? $_ENV['DNS_SERVERS'] : '94.140.14.14, 94.140.15.15');
|
||||
define('CACHE_DIR', __DIR__ . '/cache');
|
||||
define('DEBUG', isset($_ENV['DEBUG']) ? filter_var($_ENV['DEBUG'], FILTER_VALIDATE_BOOLEAN) : false);
|
||||
|
||||
/**
|
||||
* Mensagens do sistema
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
* conteúdo em cache, utilizando o sistema de arquivos como storage.
|
||||
* O cache é organizado por URLs convertidas em IDs únicos usando SHA-256.
|
||||
* O conteúdo é comprimido usando gzip para economizar espaço em disco.
|
||||
*
|
||||
* Quando o modo DEBUG está ativo, todas as operações de cache são desativadas.
|
||||
*/
|
||||
class Cache {
|
||||
/**
|
||||
|
@ -45,6 +47,11 @@ class Cache {
|
|||
* @return bool True se existir cache, False caso contrário
|
||||
*/
|
||||
public function exists($url) {
|
||||
// Se DEBUG está ativo, sempre retorna false
|
||||
if (DEBUG) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$id = $this->generateId($url);
|
||||
$cachePath = $this->cacheDir . '/' . $id . '.gz';
|
||||
return file_exists($cachePath);
|
||||
|
@ -57,6 +64,11 @@ class Cache {
|
|||
* @return string|null Conteúdo em cache ou null se não existir
|
||||
*/
|
||||
public function get($url) {
|
||||
// Se DEBUG está ativo, sempre retorna null
|
||||
if (DEBUG) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$this->exists($url)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -80,6 +92,11 @@ class Cache {
|
|||
* @return bool True se o cache foi salvo com sucesso, False caso contrário
|
||||
*/
|
||||
public function set($url, $content) {
|
||||
// Se DEBUG está ativo, não gera cache
|
||||
if (DEBUG) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$id = $this->generateId($url);
|
||||
$cachePath = $this->cacheDir . '/' . $id . '.gz';
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue