本文整理汇总了TypeScript中spica/cache.Cache.set方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Cache.set方法的具体用法?TypeScript Cache.set怎么用?TypeScript Cache.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spica/cache.Cache
的用法示例。
在下文中一共展示了Cache.set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: URL
.fmap(xhr => {
const responseURL: URL<StandardURL> = new URL(standardize(xhr.responseURL));
assert(responseURL.origin === new URL(window.location.origin).origin);
if (method === 'GET') {
const cc = new Map<string, string>(
xhr.getResponseHeader('Cache-Control')
? xhr.getResponseHeader('Cache-Control')!.trim().split(/\s*,\s*/)
.filter(v => v.length > 0)
.map(v => v.split('=').concat('') as [string, string])
: []);
for (const path of new Set([requestURL.path, responseURL.path])) {
if (xhr.getResponseHeader('ETag') && !cc.has('no-store')) {
void caches.set(path, {
etag: xhr.getResponseHeader('ETag')!,
expiry: cc.has('max-age') && !cc.has('no-cache')
? Date.now() + +cc.get('max-age')! * 1000 || 0
: 0,
xhr,
});
}
else {
void caches.delete(path);
}
}
}
return (overriddenDisplayURL: URL<StandardURL>, overriddenRequestURL: URL<StandardURL>) =>
new FetchResponse(
responseURL.path === overriddenRequestURL.path
? overriddenDisplayURL
: overriddenRequestURL.path === requestURL.path || !key
? responseURL
: overriddenDisplayURL,
xhr);
})
示例2: match
function match(pattern: string, segment: string): boolean {
assert(segment === '/' || !segment.startsWith('/'));
if (segment[0] === '.' && [...'?*'].includes(pattern[0])) return false;
const id = `${pattern}:${segment}`;
return cache.has(id)
? cache.get(id)!
: cache.set(id, match(optimize(pattern), segment));
function match(pattern: string, segment: string): boolean {
const [p = '', ...ps] = [...pattern];
const [s = '', ...ss] = [...segment];
assert(typeof p === 'string');
assert(typeof s === 'string');
switch (p) {
case '':
return s === '';
case '?':
return s !== ''
&& s !== '/'
&& match(ps.join(''), ss.join(''));
case '*':
return s === '/'
? match(ps.join(''), segment)
: Sequence
.zip(
Sequence.cycle([ps.join('')]),
Sequence.from(segment)
.tails()
.map(ss => ss.join('')))
.filter(uncurry(match))
.take(1)
.extract()
.length > 0;
default:
return s === p
&& match(ps.join(''), ss.join(''));
}
}
function optimize(pattern: string): string {
const pat = pattern.replace(/\*(\?+)\*?/g, '$1*');
return pat === pattern
? pat
: optimize(pat);
}
}
示例3: f
.fmap(f => {
if (key) {
void memory.set(key, f);
}
return f(displayURL, requestURL);
})