Feat: implement HTTP 304 with SQLite Cache (#42)

This commit is contained in:
Sukka
2024-10-09 09:25:25 +08:00
committed by GitHub
parent abf924c977
commit 07d3fdf05b
9 changed files with 144 additions and 48 deletions

View File

@@ -1,18 +1,16 @@
import { parseFelixDnsmasq } from './lib/parse-dnsmasq';
import { parseFelixDnsmasqFromResp } from './lib/parse-dnsmasq';
import { task } from './trace';
import { SHARED_DESCRIPTION } from './lib/constants';
import { createMemoizedPromise } from './lib/memo-promise';
import { TTL, deserializeArray, fsFetchCache, serializeArray, createCacheKey } from './lib/cache-filesystem';
import { deserializeArray, fsFetchCache, serializeArray, getFileContentHash } from './lib/cache-filesystem';
import { DomainsetOutput } from './lib/create-file';
const cacheKey = createCacheKey(__filename);
const url = 'https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf';
export const getAppleCdnDomainsPromise = createMemoizedPromise(() => fsFetchCache.apply(
cacheKey(url),
() => parseFelixDnsmasq(url),
export const getAppleCdnDomainsPromise = createMemoizedPromise(() => fsFetchCache.applyWithHttp304(
url,
getFileContentHash(__filename),
parseFelixDnsmasqFromResp,
{
ttl: TTL.THREE_DAYS(),
serializer: serializeArray,
deserializer: deserializeArray
}