export const getCached = async (request: HonoRequest, key: string) => {
const cacheUrl = new URL(request.url);
cacheUrl.pathname = '/' + key;
const cacheKey = new Request(cacheUrl.toString(), {
method: 'GET',
cf: {
cacheEverything: true,
cacheTtl: 86400,
},
});
const cache = caches.default;
const response = await cache.match(cacheKey);
console.log('r', response);
if (response) {
const json = await response.json();
console.log('json', json);
}
};
export const setCached = async (
request: HonoRequest,
key: string,
data: any
) => {
const cacheUrl = new URL(request.url);
cacheUrl.pathname = '/' + key;
const cacheKey = new Request(cacheUrl.toString(), {
method: 'GET',
cf: {
cacheEverything: true,
cacheTtl: 86400,
},
});
const cache = caches.default;
const response = new Response(data);
response.headers.append('Cache-Control', 's-maxage=30');
await cache.put(cacheKey, response);
};
export const getCached = async (request: HonoRequest, key: string) => {
const cacheUrl = new URL(request.url);
cacheUrl.pathname = '/' + key;
const cacheKey = new Request(cacheUrl.toString(), {
method: 'GET',
cf: {
cacheEverything: true,
cacheTtl: 86400,
},
});
const cache = caches.default;
const response = await cache.match(cacheKey);
console.log('r', response);
if (response) {
const json = await response.json();
console.log('json', json);
}
};
export const setCached = async (
request: HonoRequest,
key: string,
data: any
) => {
const cacheUrl = new URL(request.url);
cacheUrl.pathname = '/' + key;
const cacheKey = new Request(cacheUrl.toString(), {
method: 'GET',
cf: {
cacheEverything: true,
cacheTtl: 86400,
},
});
const cache = caches.default;
const response = new Response(data);
response.headers.append('Cache-Control', 's-maxage=30');
await cache.put(cacheKey, response);
};