mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Refactor: add more parsing
This commit is contained in:
@@ -4,13 +4,11 @@ import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { mkdirSync } from 'node:fs';
|
||||
import picocolors from 'picocolors';
|
||||
import { fastStringArrayJoin } from './misc';
|
||||
import { fastStringArrayJoin, identity } from './misc';
|
||||
import { performance } from 'node:perf_hooks';
|
||||
import fs from 'node:fs';
|
||||
import { stringHash } from './string-hash';
|
||||
|
||||
const identity = (x: any) => x;
|
||||
|
||||
const enum CacheStatus {
|
||||
Hit = 'hit',
|
||||
Stale = 'stale',
|
||||
@@ -186,7 +184,7 @@ export class Cache<S = string> {
|
||||
if (cached == null) {
|
||||
console.log(picocolors.yellow('[cache] miss'), picocolors.gray(key), picocolors.gray(`ttl: ${TTL.humanReadable(ttl)}`));
|
||||
|
||||
const serializer = 'serializer' in opt ? opt.serializer : identity;
|
||||
const serializer = 'serializer' in opt ? opt.serializer : identity as any;
|
||||
|
||||
const promise = fn();
|
||||
|
||||
@@ -202,7 +200,7 @@ export class Cache<S = string> {
|
||||
this.updateTtl(key, ttl);
|
||||
}
|
||||
|
||||
const deserializer = 'deserializer' in opt ? opt.deserializer : identity;
|
||||
const deserializer = 'deserializer' in opt ? opt.deserializer : identity as any;
|
||||
return deserializer(cached);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user