Skip to content

Commit cbb6698

Browse files
committed
add files apiRest.com
1 parent 79ea8c2 commit cbb6698

27 files changed

Lines changed: 2409 additions & 0 deletions

File tree

CacheExplorer/index.html

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<!DOCTYPE html>
2+
<html lang="pt-BR">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Explorador Interativo de Cache de Servidor</title>
7+
<script src="https://cdn.tailwindcss.com"></script>
8+
<link rel="preconnect" href="https://fonts.googleapis.com">
9+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
10+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap" rel="stylesheet">
11+
<!-- Chosen Palette: Calm Harmony (Stone, Teal) -->
12+
<!-- Application Structure Plan: A thematic, single-page application designed for conceptual exploration. The structure includes: a hero definition, a benefits section, a central interactive diagram demonstrating the request/response flow with and without cache, a tabbed section for cache types, and a final section with side-by-side real-world examples. This non-linear, thematic structure was chosen over a simple text layout to make the abstract concept of caching tangible and engaging, allowing users to learn by doing and seeing rather than just reading. -->
13+
<!-- Visualization & Content Choices: The core of the report is the process flow, which is best represented by a custom interactive diagram (HTML/CSS/JS) instead of a data chart. Report Info: Request/Response flow -> Goal: Demonstrate Process -> Viz: Interactive Diagram -> Interaction: User-triggered simulation of cached vs. uncached requests -> Justification: Actively demonstrates the performance difference, which is the key takeaway. Report Info: Cache Types -> Goal: Organize -> Viz: Tabbed Interface -> Interaction: Click to reveal -> Justification: Segments information for clarity. The application avoids traditional charts as the source material is qualitative. -->
14+
<!-- CONFIRMATION: NO SVG graphics used. NO Mermaid JS used. -->
15+
<link rel="stylesheet" href="style.css">
16+
</head>
17+
<body class="antialiased">
18+
19+
<header class="bg-white/80 backdrop-blur-md sticky top-0 z-20 border-b border-stone-200">
20+
<nav class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
21+
<div class="flex items-center justify-between h-16">
22+
<div class="flex-shrink-0">
23+
<h1 class="text-xl font-bold text-stone-700">Explorador de Cache</h1>
24+
</div>
25+
<div class="hidden md:block">
26+
<div class="ml-10 flex items-baseline space-x-4">
27+
<a href="#intro" class="nav-link px-3 py-2 text-sm font-medium text-stone-600 border-b-2 border-transparent">O Que É?</a>
28+
<a href="#how-it-works" class="nav-link px-3 py-2 text-sm font-medium text-stone-600 border-b-2 border-transparent">Como Funciona?</a>
29+
<a href="#types" class="nav-link px-3 py-2 text-sm font-medium text-stone-600 border-b-2 border-transparent">Tipos de Cache</a>
30+
<a href="#examples" class="nav-link px-3 py-2 text-sm font-medium text-stone-600 border-b-2 border-transparent">Exemplos</a>
31+
</div>
32+
</div>
33+
</div>
34+
</nav>
35+
</header>
36+
37+
<main class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
38+
39+
<section id="intro" class="text-center py-16">
40+
<h2 class="text-4xl md:text-5xl font-bold text-stone-800 mb-4">O que é Cache de Servidor?</h2>
41+
<p class="max-w-3xl mx-auto text-lg text-stone-600">
42+
É a habilidade de um sistema de armazenar e reutilizar respostas a solicitações anteriores, em vez de processar a mesma solicitação repetidamente. O objetivo principal é aumentar drasticamente a eficiência e o desempenho, entregando conteúdo aos usuários de forma muito mais rápida.
43+
</p>
44+
</section>
45+
46+
<section id="how-it-works" class="py-16">
47+
<div class="text-center mb-12">
48+
<h2 class="text-3xl font-bold text-stone-800">Como o Cache Funciona na Prática?</h2>
49+
<p class="mt-2 text-stone-600 max-w-2xl mx-auto">Esta simulação interativa mostra o fluxo de uma solicitação de dados com e sem cache. Clique nos botões para ver a diferença no tempo e no caminho percorrido pela informação.</p>
50+
</div>
51+
52+
<div class="bg-white p-6 md:p-8 rounded-xl shadow-md">
53+
<div id="diagram-container" class="relative h-64 md:h-80 flex items-center justify-between">
54+
<div id="user" class="diagram-box w-24 md:w-32">
55+
<span class="text-2xl">👤</span>
56+
<p class="font-semibold mt-2">Usuário</p>
57+
</div>
58+
<div id="cache" class="diagram-box w-24 md:w-32">
59+
<span class="text-2xl">🗄️</span>
60+
<p class="font-semibold mt-2">Cache</p>
61+
<span id="cache-status" class="text-xs text-stone-500">(Vazio)</span>
62+
</div>
63+
<div id="server" class="diagram-box w-24 md:w-32">
64+
<span class="text-2xl">🖥️</span>
65+
<p class="font-semibold mt-2">Servidor</p>
66+
<span id="server-status" class="text-xs text-stone-500">(Ocioso)</span>
67+
</div>
68+
<div id="packet" class="request-packet">Req</div>
69+
</div>
70+
71+
<div class="mt-8 flex flex-col sm:flex-row justify-center items-center gap-4">
72+
<button id="no-cache-btn" class="w-full sm:w-auto bg-teal-600 text-white font-semibold py-2 px-6 rounded-lg hover:bg-teal-700 transition-colors">
73+
Simular Requisição (Sem Cache)
74+
</button>
75+
<button id="with-cache-btn" class="w-full sm:w-auto bg-stone-500 text-white font-semibold py-2 px-6 rounded-lg hover:bg-stone-600 transition-colors">
76+
Simular Requisição (Com Cache)
77+
</button>
78+
<button id="reset-btn" class="w-full sm:w-auto bg-gray-300 text-stone-800 font-semibold py-2 px-6 rounded-lg hover:bg-gray-400 transition-colors">
79+
Resetar Simulação
80+
</button>
81+
</div>
82+
<div id="simulation-log" class="mt-6 text-center text-stone-600 h-6"></div>
83+
</div>
84+
</section>
85+
86+
<section id="types" class="py-16">
87+
<div class="text-center mb-12">
88+
<h2 class="text-3xl font-bold text-stone-800">Tipos de Implementação de Cache</h2>
89+
<p class="mt-2 text-stone-600 max-w-2xl mx-auto">O cache pode ser implementado em diferentes pontos do fluxo de comunicação. Clique para explorar os tipos mais comuns.</p>
90+
</div>
91+
92+
<div class="grid grid-cols-1 md:grid-cols-3 gap-8">
93+
<div class="cache-type-card bg-white p-6 rounded-xl shadow-md cursor-pointer border-2 border-transparent hover:border-teal-500 transition-all" data-type="browser">
94+
<h3 class="text-xl font-bold text-stone-800 mb-2">Cache no Navegador</h3>
95+
<p class="text-stone-600">Seu próprio navegador armazena arquivos (imagens, CSS) de sites que você visita para acelerar o carregamento em visitas futuras.</p>
96+
</div>
97+
<div class="cache-type-card bg-white p-6 rounded-xl shadow-md cursor-pointer border-2 border-transparent hover:border-teal-500 transition-all" data-type="proxy">
98+
<h3 class="text-xl font-bold text-stone-800 mb-2">Cache de Proxy / CDN</h3>
99+
<p class="text-stone-600">Servidores intermediários armazenam respostas populares para entregá-las a múltiplos usuários sem contatar o servidor de origem.</p>
100+
</div>
101+
<div class="cache-type-card bg-white p-6 rounded-xl shadow-md cursor-pointer border-2 border-transparent hover:border-teal-500 transition-all" data-type="server">
102+
<h3 class="text-xl font-bold text-stone-800 mb-2">Cache no Servidor</h3>
103+
<p class="text-stone-600">O próprio servidor de origem armazena em memória dados ou partes de páginas que são frequentemente solicitadas para evitar consultas repetidas ao banco de dados.</p>
104+
</div>
105+
</div>
106+
107+
<div id="type-details" class="mt-8 bg-white p-8 rounded-xl shadow-inner min-h-[100px] text-stone-700">
108+
<p>Selecione um tipo de cache acima para ver mais detalhes.</p>
109+
</div>
110+
</section>
111+
112+
<section id="examples" class="py-16">
113+
<div class="text-center mb-12">
114+
<h2 class="text-3xl font-bold text-stone-800">Exemplos Práticos</h2>
115+
<p class="mt-2 text-stone-600 max-w-2xl mx-auto">Veja como o cache impacta o desempenho de aplicações comuns, como um site de notícias e uma loja virtual.</p>
116+
</div>
117+
118+
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
119+
<div class="bg-white p-8 rounded-xl shadow-md">
120+
<h3 class="text-2xl font-bold text-stone-800 mb-4">📰 Site de Notícias</h3>
121+
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
122+
<div>
123+
<h4 class="font-semibold text-red-600 mb-2">❌ Sem Cache</h4>
124+
<p class="text-sm text-stone-600">Para cada visitante, o servidor busca o artigo no banco de dados, monta a página e a envia. Isso sobrecarrega o servidor com tráfego intenso.</p>
125+
</div>
126+
<div>
127+
<h4 class="font-semibold text-green-600 mb-2">✅ Com Cache</h4>
128+
<p class="text-sm text-stone-600">A página do artigo é gerada uma vez e armazenada. Milhares de visitantes recebem essa cópia em cache instantaneamente, aliviando o servidor.</p>
129+
</div>
130+
</div>
131+
</div>
132+
<div class="bg-white p-8 rounded-xl shadow-md">
133+
<h3 class="text-2xl font-bold text-stone-800 mb-4">🛒 E-commerce</h3>
134+
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
135+
<div>
136+
<h4 class="font-semibold text-red-600 mb-2">❌ Sem Cache</h4>
137+
<p class="text-sm text-stone-600">A página inicial com "produtos em destaque" exige uma consulta complexa ao banco de dados para cada usuário, tornando o carregamento lento.</p>
138+
</div>
139+
<div>
140+
<h4 class="font-semibold text-green-600 mb-2">✅ Com Cache</h4>
141+
<p class="text-sm text-stone-600">A lista de produtos em destaque é salva em cache por uma hora. Todos os usuários veem a página carregar instantaneamente, melhorando a experiência.</p>
142+
</div>
143+
</div>
144+
</div>
145+
</div>
146+
</section>
147+
148+
</main>
149+
150+
<footer class="bg-stone-800 text-stone-300 mt-16">
151+
<div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-6 text-center">
152+
<p>Uma demonstração interativa sobre a importância do cache.</p>
153+
</div>
154+
</footer>
155+
156+
<script src="script.js"></script>
157+
</body>
158+
</html>

CacheExplorer/script.js

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
document.addEventListener('DOMContentLoaded', () => {
2+
3+
const noCacheBtn = document.getElementById('no-cache-btn');
4+
const withCacheBtn = document.getElementById('with-cache-btn');
5+
const resetBtn = document.getElementById('reset-btn');
6+
7+
const userEl = document.getElementById('user');
8+
const cacheEl = document.getElementById('cache');
9+
const serverEl = document.getElementById('server');
10+
const packetEl = document.getElementById('packet');
11+
const cacheStatusEl = document.getElementById('cache-status');
12+
const serverStatusEl = document.getElementById('server-status');
13+
const simulationLogEl = document.getElementById('simulation-log');
14+
15+
let isCached = false;
16+
let isAnimating = false;
17+
18+
const getPosition = (el) => {
19+
const rect = el.getBoundingClientRect();
20+
const containerRect = el.parentElement.getBoundingClientRect();
21+
return {
22+
x: rect.left - containerRect.left + rect.width / 2 - packetEl.offsetWidth / 2,
23+
y: rect.top - containerRect.top + rect.height / 2 - packetEl.offsetHeight / 2,
24+
};
25+
};
26+
27+
const animatePacket = (startEl, endEl, duration) => {
28+
return new Promise(resolve => {
29+
const startPos = getPosition(startEl);
30+
const endPos = getPosition(endEl);
31+
packetEl.style.transition = `all ${duration}s ease-in-out`;
32+
packetEl.style.left = `${startPos.x}px`;
33+
packetEl.style.top = `${startPos.y}px`;
34+
packetEl.style.opacity = '1';
35+
36+
setTimeout(() => {
37+
packetEl.style.left = `${endPos.x}px`;
38+
packetEl.style.top = `${endPos.y}px`;
39+
}, 100);
40+
41+
setTimeout(resolve, duration * 1000 + 100);
42+
});
43+
};
44+
45+
const resetState = () => {
46+
isCached = false;
47+
isAnimating = false;
48+
cacheStatusEl.textContent = '(Vazio)';
49+
cacheStatusEl.style.color = '';
50+
serverStatusEl.textContent = '(Ocioso)';
51+
cacheEl.classList.remove('processing');
52+
serverEl.classList.remove('processing');
53+
packetEl.style.opacity = '0';
54+
simulationLogEl.textContent = '';
55+
};
56+
57+
noCacheBtn.addEventListener('click', async () => {
58+
if (isAnimating) return;
59+
isAnimating = true;
60+
simulationLogEl.textContent = 'Iniciando requisição sem cache...';
61+
62+
serverStatusEl.textContent = '(Processando...)';
63+
serverEl.classList.add('processing');
64+
65+
await animatePacket(userEl, serverEl, 1.5);
66+
simulationLogEl.textContent = 'Servidor processando a requisição...';
67+
68+
await new Promise(r => setTimeout(r, 1500));
69+
70+
serverStatusEl.textContent = '(Ocioso)';
71+
serverEl.classList.remove('processing');
72+
73+
await animatePacket(serverEl, userEl, 1.5);
74+
simulationLogEl.textContent = 'Requisição sem cache concluída. (Lento)';
75+
76+
packetEl.style.opacity = '0';
77+
isAnimating = false;
78+
});
79+
80+
withCacheBtn.addEventListener('click', async () => {
81+
if (isAnimating) return;
82+
isAnimating = true;
83+
84+
if (!isCached) {
85+
simulationLogEl.textContent = 'Primeira requisição: buscando no servidor...';
86+
serverStatusEl.textContent = '(Processando...)';
87+
serverEl.classList.add('processing');
88+
89+
await animatePacket(userEl, serverEl, 1.5);
90+
simulationLogEl.textContent = 'Servidor processando e salvando no cache...';
91+
92+
await new Promise(r => setTimeout(r, 1500));
93+
94+
isCached = true;
95+
cacheStatusEl.textContent = '(Preenchido)';
96+
cacheStatusEl.style.color = '#10b981';
97+
serverStatusEl.textContent = '(Ocioso)';
98+
serverEl.classList.remove('processing');
99+
100+
await animatePacket(serverEl, userEl, 1.5);
101+
simulationLogEl.textContent = 'Dados entregues e cacheados.';
102+
} else {
103+
simulationLogEl.textContent = 'Requisição subsequente: buscando no cache...';
104+
cacheEl.classList.add('processing');
105+
106+
await animatePacket(userEl, cacheEl, 0.7);
107+
simulationLogEl.textContent = 'Cache encontrado! Entregando dados...';
108+
109+
await new Promise(r => setTimeout(r, 500));
110+
cacheEl.classList.remove('processing');
111+
112+
await animatePacket(cacheEl, userEl, 0.7);
113+
simulationLogEl.textContent = 'Requisição com cache concluída. (Rápido!)';
114+
}
115+
116+
packetEl.style.opacity = '0';
117+
isAnimating = false;
118+
});
119+
120+
resetBtn.addEventListener('click', resetState);
121+
122+
const cacheTypeCards = document.querySelectorAll('.cache-type-card');
123+
const typeDetailsEl = document.getElementById('type-details');
124+
const typeDetailsContent = {
125+
browser: `
126+
<h4 class="text-lg font-bold mb-2">Detalhes do Cache no Navegador</h4>
127+
<p>O navegador armazena arquivos estáticos como imagens, CSS e JavaScript no disco local do seu computador. Quando você visita o mesmo site novamente, o navegador carrega esses arquivos diretamente do seu disco em vez de baixá-los da internet, resultando em um carregamento de página quase instantâneo.</p>
128+
`,
129+
proxy: `
130+
<h4 class="text-lg font-bold mb-2">Detalhes do Cache de Proxy / CDN</h4>
131+
<p>Uma Content Delivery Network (CDN) é uma rede de servidores proxy distribuídos globalmente. Eles armazenam cópias do conteúdo de um site. Quando um usuário faz uma solicitação, a CDN a entrega a partir do servidor mais próximo geograficamente, reduzindo a latência e a carga no servidor original.</p>
132+
`,
133+
server: `
134+
<h4 class="text-lg font-bold mb-2">Detalhes do Cache no Servidor</h4>
135+
<p>Esta técnica envolve o armazenamento de dados frequentemente acessados na memória RAM do próprio servidor. Por exemplo, os resultados de uma consulta de banco de dados pesada podem ser cacheados. A próxima vez que esses dados forem necessários, eles são lidos da memória ultrarrápida em vez de executar a consulta novamente, acelerando a geração da página.</p>
136+
`
137+
};
138+
139+
cacheTypeCards.forEach(card => {
140+
card.addEventListener('click', () => {
141+
const type = card.dataset.type;
142+
typeDetailsEl.innerHTML = typeDetailsContent[type];
143+
144+
cacheTypeCards.forEach(c => c.classList.remove('border-teal-500', 'bg-teal-50'));
145+
card.classList.add('border-teal-500', 'bg-teal-50');
146+
});
147+
});
148+
149+
const navLinks = document.querySelectorAll('.nav-link');
150+
const sections = document.querySelectorAll('section');
151+
152+
window.addEventListener('scroll', () => {
153+
let current = '';
154+
sections.forEach(section => {
155+
const sectionTop = section.offsetTop;
156+
if (pageYOffset >= sectionTop - 80) {
157+
current = section.getAttribute('id');
158+
}
159+
});
160+
161+
navLinks.forEach(link => {
162+
link.classList.remove('active-nav');
163+
if (link.getAttribute('href') === `#${current}`) {
164+
link.classList.add('active-nav');
165+
}
166+
});
167+
});
168+
});

CacheExplorer/style.css

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
body {
2+
font-family: 'Inter', sans-serif;
3+
background-color: #f5f5f4; /* stone-100 */
4+
color: #292524; /* stone-800 */
5+
}
6+
.nav-link {
7+
transition: color 0.3s, border-color 0.3s;
8+
}
9+
.nav-link:hover {
10+
color: #0d9488; /* teal-600 */
11+
}
12+
.active-tab {
13+
border-color: #0d9488; /* teal-600 */
14+
color: #0d9488;
15+
font-weight: 500;
16+
}
17+
.diagram-box {
18+
border: 2px solid #a8a29e; /* stone-400 */
19+
border-radius: 0.5rem;
20+
padding: 1rem;
21+
text-align: center;
22+
transition: all 0.3s ease-in-out;
23+
}
24+
.diagram-line {
25+
position: absolute;
26+
background-color: #a8a29e; /* stone-400 */
27+
transform-origin: left center;
28+
}
29+
.request-packet {
30+
position: absolute;
31+
width: 2rem;
32+
height: 2rem;
33+
background-color: #14b8a6; /* teal-500 */
34+
border-radius: 9999px;
35+
display: flex;
36+
align-items: center;
37+
justify-content: center;
38+
color: white;
39+
font-size: 0.75rem;
40+
transition: all 1.5s ease-in-out;
41+
opacity: 0;
42+
z-index: 10;
43+
}
44+
.processing {
45+
animation: pulse 1s infinite;
46+
}
47+
@keyframes pulse {
48+
0%, 100% { box-shadow: 0 0 0 0 rgba(13, 148, 136, 0.7); }
49+
50% { box-shadow: 0 0 0 10px rgba(13, 148, 136, 0); }
50+
}

0 commit comments

Comments
 (0)