mirror of
https://github.com/manualdousuario/marreta.git
synced 2025-09-01 18:20:22 +00:00
sistema de compressão dos caches em html
This commit is contained in:
parent
380d101bac
commit
4ed8af9ad8
3 changed files with 34 additions and 8 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,6 +3,7 @@ composer.lock
|
|||
.env
|
||||
app/logs/*.log
|
||||
app/cache/*.html
|
||||
app/cache/*.gz
|
||||
TODO.md
|
||||
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/composer,windows,macos,linux
|
||||
|
|
15
Dockerfile
15
Dockerfile
|
@ -1,6 +1,15 @@
|
|||
FROM php:8.0-fpm
|
||||
|
||||
RUN apt-get update && apt-get install -y nginx nano procps unzip git htop
|
||||
# Instala dependências e extensões do PHP
|
||||
RUN apt-get update && apt-get install -y \
|
||||
nginx \
|
||||
nano \
|
||||
procps \
|
||||
zip \
|
||||
git \
|
||||
htop \
|
||||
libzip-dev \
|
||||
&& docker-php-ext-install zip
|
||||
|
||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||
|
||||
|
@ -12,13 +21,13 @@ COPY app/ /app/
|
|||
WORKDIR /app
|
||||
RUN composer install --no-interaction --optimize-autoloader
|
||||
|
||||
# Copy and set permissions for entrypoint script
|
||||
# Copia e configura permissões do script de inicialização
|
||||
COPY docker-entrypoint.sh /usr/local/bin/
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
RUN mkdir -p /app/cache /app/logs
|
||||
|
||||
# Set base permissions for /app
|
||||
# Configura permissões base para o diretório /app
|
||||
RUN chown -R www-data:www-data /app \
|
||||
&& chmod -R 755 /app
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* Esta classe implementa funcionalidades para armazenar e recuperar
|
||||
* 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.
|
||||
*/
|
||||
class Cache {
|
||||
/**
|
||||
|
@ -45,7 +46,7 @@ class Cache {
|
|||
*/
|
||||
public function exists($url) {
|
||||
$id = $this->generateId($url);
|
||||
$cachePath = $this->cacheDir . '/' . $id . '.html';
|
||||
$cachePath = $this->cacheDir . '/' . $id . '.gz';
|
||||
return file_exists($cachePath);
|
||||
}
|
||||
|
||||
|
@ -60,8 +61,15 @@ class Cache {
|
|||
return null;
|
||||
}
|
||||
$id = $this->generateId($url);
|
||||
$cachePath = $this->cacheDir . '/' . $id . '.html';
|
||||
return file_get_contents($cachePath);
|
||||
$cachePath = $this->cacheDir . '/' . $id . '.gz';
|
||||
|
||||
// Lê e descomprime o conteúdo
|
||||
$compressedContent = file_get_contents($cachePath);
|
||||
if ($compressedContent === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return gzdecode($compressedContent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,10 +77,18 @@ class Cache {
|
|||
*
|
||||
* @param string $url URL associada ao conteúdo
|
||||
* @param string $content Conteúdo a ser armazenado em cache
|
||||
* @return bool True se o cache foi salvo com sucesso, False caso contrário
|
||||
*/
|
||||
public function set($url, $content) {
|
||||
$id = $this->generateId($url);
|
||||
$cachePath = $this->cacheDir . '/' . $id . '.html';
|
||||
file_put_contents($cachePath, $content);
|
||||
$cachePath = $this->cacheDir . '/' . $id . '.gz';
|
||||
|
||||
// Comprime o conteúdo usando gzip
|
||||
$compressedContent = gzencode($content, 3);
|
||||
if ($compressedContent === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return file_put_contents($cachePath, $compressedContent) !== false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue