本文整理匯總了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)
}
示例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;
}
示例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
}
示例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);
}
示例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`)
}
//.........這裏部分代碼省略.........