Skip to content

Commit 1c89af5

Browse files
committed
feat: remove cache management endpoints and related tests from API
1 parent b33313b commit 1c89af5

File tree

9 files changed

+9
-378
lines changed

9 files changed

+9
-378
lines changed

README.md

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ The API will be available at <http://localhost:3000>
3030
- **Cache Headers**: 6-hour cache control for static data
3131
- **Health Check**: GET `/` returns health status
3232
- **RESTful API**: All endpoints follow REST conventions
33-
- **Backend caching**: Some responses are cached on the backend for 1 hours to improve latency
3433

3534
### `GET /`
3635

@@ -501,51 +500,6 @@ Returns a JSON object with the following schema:
501500
]
502501
```
503502
504-
### `GET /cache-stats`
505-
506-
Provides statistics about the API's cache.
507-
508-
```bash
509-
curl --request GET \
510-
--url 'https://{{HOST}}/v1/cache-stats'
511-
```
512-
513-
Returns a JSON object with the following schema:
514-
515-
```json
516-
{
517-
"cache_hits": 12345,
518-
"cache_misses": 6789,
519-
"last_cleared": "2023-10-01T12:00:00Z"
520-
}
521-
```
522-
523-
### `POST /v1/cache-reset`
524-
525-
Resets all caches in the API. This endpoint requires a POST request.
526-
527-
```bash
528-
curl --request POST \
529-
--url 'https://{{HOST}}/v1/cache-reset'
530-
```
531-
532-
Returns a JSON object with the following schema:
533-
534-
```json
535-
{
536-
"success": true,
537-
"message": "All caches have been reset",
538-
"before": {
539-
"queryCache": 150,
540-
"dateCache": 12
541-
},
542-
"after": {
543-
"queryCache": 0,
544-
"dateCache": 0
545-
}
546-
}
547-
```
548-
549503
## Testing
550504
551505
```bash
@@ -667,34 +621,4 @@ Response:
667621
}
668622
```
669623
670-
## Cache Stats Private Endpoint
671-
672-
The Cache Stats private endpoint provides information about the API's cache performance, including cache hits, misses, and the last time the cache was cleared. This endpoint is useful for monitoring and debugging cache behavior.
673-
674-
```bash
675-
curl "https://tech-report-api-dev-226352634162.us-central1.run.app/v1/cache-stats" \
676-
-H "Authorization: bearer $(gcloud auth print-identity-token)"
677-
```
678-
679-
Returns a JSON object with the following schema:
680624
681-
```json
682-
{
683-
"queryCache": {
684-
"total": 3220,
685-
"valid": 2437,
686-
"expired": 783,
687-
"ttl": 3600000
688-
},
689-
"dateCache": {
690-
"total": 4,
691-
"valid": 4,
692-
"expired": 0,
693-
"ttl": 3600000
694-
},
695-
"config": {
696-
"maxCacheSize": 5000,
697-
"cleanupStrategy": "size-based-lru"
698-
}
699-
}
700-
```

src/__tests__/routes.test.js

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -383,37 +383,6 @@ describe('API Routes', () => {
383383
});
384384
});
385385

386-
describe('Cache Management', () => {
387-
it('should provide cache stats', async () => {
388-
const res = await request(app)
389-
.get('/v1/cache-stats')
390-
.expect(200);
391-
392-
expect(res.body).toHaveProperty('queryCache');
393-
expect(res.body).toHaveProperty('dateCache');
394-
expect(res.body).toHaveProperty('config');
395-
});
396-
397-
it('should reset cache on POST request', async () => {
398-
const res = await request(app)
399-
.post('/v1/cache-reset')
400-
.expect(200);
401-
402-
expect(res.body).toHaveProperty('success', true);
403-
expect(res.body).toHaveProperty('message');
404-
expect(res.body).toHaveProperty('before');
405-
expect(res.body).toHaveProperty('after');
406-
});
407-
408-
it('should handle cache reset OPTIONS request', async () => {
409-
const res = await request(app)
410-
.options('/v1/cache-reset')
411-
.expect(204);
412-
413-
expect(res.headers['access-control-allow-methods']).toContain('POST');
414-
});
415-
});
416-
417386
describe('GET /v1/static/*', () => {
418387
beforeEach(() => {
419388
// Reset all mocks before each test

src/controllers/categoriesController.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,7 @@ const listCategories = async (req, res) => {
5353
return data;
5454
};
5555

56-
// Include onlyname and fields in cache key calculation
57-
const customCacheKeyData = {
58-
onlyname: req.query.onlyname || false,
59-
fields: req.query.fields
60-
};
61-
62-
await executeQuery(req, res, 'categories', queryBuilder, dataProcessor, customCacheKeyData);
56+
await executeQuery(req, res, 'categories', queryBuilder, dataProcessor);
6357
};
6458

6559
export { listCategories };

src/controllers/cdnController.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ export const proxyReportsFile = async (req, res, filePath) => {
6262

6363
// Set response headers
6464
res.setHeader('Content-Type', contentType);
65-
res.setHeader('Cache-Control', 'public, max-age=86400'); // 24 hours
66-
res.setHeader('Access-Control-Allow-Origin', '*');
67-
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
68-
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
6965

7066
if (metadata.etag) {
7167
res.setHeader('ETag', metadata.etag);

src/controllers/reportController.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import {
66
validateRequiredParams,
77
sendValidationError,
88
getLatestDate,
9-
generateQueryCacheKey,
10-
getCachedQueryResult,
11-
setCachedQueryResult,
129
handleControllerError,
1310
validateArrayParameter
1411
} from '../utils/controllerHelpers.js';
@@ -87,24 +84,6 @@ const createReportController = (reportType) => {
8784
startDate = await getLatestDate(firestore, config.table);
8885
}
8986

90-
// Create cache key for this specific query
91-
const queryFilters = {
92-
geo: params.geo,
93-
rank: params.rank,
94-
technology: techArray,
95-
startDate: startDate,
96-
endDate: params.end
97-
};
98-
const cacheKey = generateQueryCacheKey(config.table, queryFilters);
99-
100-
// Check cache first
101-
const cachedResult = getCachedQueryResult(cacheKey);
102-
if (cachedResult) {
103-
res.statusCode = 200;
104-
res.end(JSON.stringify(cachedResult));
105-
return;
106-
}
107-
10887
// Build Firestore query
10988
let query = firestore.collection(config.table);
11089

@@ -136,9 +115,6 @@ const createReportController = (reportType) => {
136115
data.push(doc.data());
137116
});
138117

139-
// Cache the result
140-
setCachedQueryResult(cacheKey, data);
141-
142118
// Send response
143119
res.statusCode = 200;
144120
res.end(JSON.stringify(data));

src/controllers/technologiesController.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,7 @@ const listTechnologies = async (req, res) => {
6666
return data;
6767
};
6868

69-
// Include onlyname and fields in cache key calculation
70-
const customCacheKeyData = {
71-
onlyname: req.query.onlyname || false,
72-
fields: req.query.fields
73-
};
74-
75-
await executeQuery(req, res, 'technologies', queryBuilder, dataProcessor, customCacheKeyData);
69+
await executeQuery(req, res, 'technologies', queryBuilder, dataProcessor);
7670
};
7771

7872
export {

src/index.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,6 @@ const handleRequest = async (req, res) => {
162162
} else if (pathname === '/v1/versions' && req.method === 'GET') {
163163
const { listVersions } = await getController('versions');
164164
await listVersions(req, res);
165-
} else if (pathname === '/v1/cache-stats' && req.method === 'GET') {
166-
// Cache monitoring endpoint
167-
const { getCacheStats } = await import('./utils/controllerHelpers.js');
168-
const stats = getCacheStats();
169-
sendJSONResponse(res, stats);
170-
} else if (pathname === '/v1/cache-reset' && req.method === 'POST') {
171-
// Cache reset endpoint
172-
const { resetCache } = await import('./utils/controllerHelpers.js');
173-
const result = resetCache();
174-
sendJSONResponse(res, result);
175165
} else if (pathname.startsWith('/v1/static/') && req.method === 'GET') {
176166
// GCS proxy endpoint for reports files
177167
const filePath = pathname.replace('/v1/static/', '');

0 commit comments

Comments
 (0)