本文整理汇总了TypeScript中lru-cache.set函数的典型用法代码示例。如果您正苦于以下问题:TypeScript set函数的具体用法?TypeScript set怎么用?TypeScript set使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: writeAuthTimestamp
private async writeAuthTimestamp(bucketAddress: string, timestamp: number): Promise<void> {
// Recheck cache for a larger timestamp to avoid race conditions from slow storage.
let cachedTimestamp = this.cache.get(bucketAddress)
if (cachedTimestamp && cachedTimestamp > timestamp) {
return
}
const authTimestampFileDir = this.getAuthTimestampFileDir(bucketAddress)
// Convert our number to a Buffer.
const contentBuffer = Buffer.from(timestamp.toString(), 'utf8')
// Wrap the buffer in a stream for driver consumption.
const contentStream = new Readable()
contentStream.push(contentBuffer, 'utf8')
contentStream.push(null) // Mark EOF
await this.driver.performWrite({
storageTopLevel: authTimestampFileDir,
path: AUTH_TIMESTAMP_FILE_NAME,
stream: contentStream,
contentLength: contentBuffer.length,
contentType: 'text/plain; charset=UTF-8'
})
// In a race condition, use the newest timestamp.
cachedTimestamp = this.cache.get(bucketAddress)
if (cachedTimestamp && cachedTimestamp > timestamp) {
timestamp = cachedTimestamp
}
this.cache.set(bucketAddress, timestamp)
}
开发者ID:blockstack,项目名称:blockstack-registrar,代码行数:34,代码来源:revocations.ts
示例2: getCacheKey
export async function callApi<T = void>(
fetchOptions: KFetchOptions,
options?: KFetchKibanaOptions
): Promise<T> {
const cacheKey = getCacheKey(fetchOptions);
const cacheResponse = cache.get(cacheKey);
if (cacheResponse) {
return cacheResponse;
}
const combinedFetchOptions = fetchOptionsWithDebug(fetchOptions);
const res = await kfetch(combinedFetchOptions, options);
if (isCachable(fetchOptions)) {
cache.set(cacheKey, res);
}
return res;
}
开发者ID:elastic,项目名称:kibana,代码行数:19,代码来源:callApi.ts
示例3: getAuthTimestamp
async getAuthTimestamp(bucketAddress: string): Promise<number> {
// First perform fast check if auth number exists in cache..
let authTimestamp = this.cache.get(bucketAddress)
if (authTimestamp) {
return authTimestamp
}
// Nothing in cache, perform slower driver read.
authTimestamp = await this.readAuthTimestamp(bucketAddress)
// Recheck cache for a larger timestamp to avoid race conditions from slow storage.
const cachedTimestamp = this.cache.get(bucketAddress)
if (cachedTimestamp && cachedTimestamp > authTimestamp) {
authTimestamp = cachedTimestamp
}
// Cache result for fast lookup later.
this.cache.set(bucketAddress, authTimestamp)
return authTimestamp
}
开发者ID:blockstack,项目名称:blockstack-registrar,代码行数:21,代码来源:revocations.ts
示例4: set
async set(key: string, value: V, options?: { ttl?: number }) {
const maxAge = options && options.ttl && options.ttl * 1000;
this.store.set(key, value, maxAge);
}
开发者ID:apollostack,项目名称:apollo-server,代码行数:4,代码来源:InMemoryLRUCache.ts
示例5: Promise
new Promise(async (resolve, reject) => {
const start: boolean | number = __DEV__ && Date.now()
const { ctx } = context
const { app, createApollo, router, store } = createApp()
const { url } = ctx
const { fullPath } = router.resolve(url).route
if (fullPath !== url) {
return reject({ status: 302, url: fullPath })
}
const axios = _axios.create({
headers: ctx.headers,
})
let apollo = cache.get(url)
if (!apollo) {
cache.set(url, (apollo = createApollo()))
}
const translator = createTranslator({
locale: context.locale,
defaultLocale: DEFAULT_LOCALE,
})
const translate = createTranslate(translator)
Object.assign(context, {
apollo,
axios,
translate,
translator,
})
axios.interceptors.response.use(
response => {
const { headers } = response
const cookies = headers[SET_COOKIE] as string[]
parseSetCookies(cookies).forEach(
({ name, expires, httponly: httpOnly, path, value }) => {
if (name !== KOA_SESS_SIG) {
ctx.cookies.set(name, value, {
expires: expires && new Date(expires),
httpOnly,
path,
})
}
},
)
return response
},
e => {
const { data, headers } = e.response
ctx.set(headers)
reject(data)
},
)
await store.dispatch('fetchInfo', { apollo, axios })
router.push(ctx.url)
router.onReady(async () => {
const matched = router.getMatchedComponents()
if (!matched.length) {
// tslint:disable-next-line:no-console
console.error('no matched components')
return reject({ status: 404 })
}
const { currentRoute: route } = router
if (route.fullPath !== url) {
return reject({ status: 302, url: route.fullPath })
}
try {
await Promise.all(
matched.map(
({ options, asyncData = options && options.asyncData }: any) =>
asyncData &&
asyncData({ apollo, axios, route, store, translate }),
),
)
await translate.cache.prefetch()
} catch (e) {
return reject(e.response ? e.response.data : e)
}
if (__DEV__) {
// tslint:disable-next-line:no-console
console.log(`data pre-fetch: ${Date.now() - (start as number)}ms`)
}
//.........这里部分代码省略.........
开发者ID:JounQin,项目名称:blog,代码行数:101,代码来源:entry-server.ts
注:本文中的lru-cache.set函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论