當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript lru-cache.get函數代碼示例

本文整理匯總了TypeScript中lru-cache.get函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript get函數的具體用法?TypeScript get怎麽用?TypeScript get使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了get函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: test

test('request will refresh the cache with forceUpdate config', async t => {

	const adapterCb = spy();
	const mockedAdapter = genMockAdapter(adapterCb);
	const cache = new LRUCache<string, AxiosPromise>();
	const http = axios.create({
		adapter: cacheAdapterEnhancer(mockedAdapter, { enabledByDefault: true, cacheFlag: 'cache', defaultCache: cache }),
	});

	const onSuccess = spy();
	await http.get('/users').then(onSuccess);
	const responed1 = await cache.get('/users') as any;
	await http.get('/users', { forceUpdate: true } as any).then(onSuccess);
	const responed2 = await cache.get('/users') as any;
	t.is(adapterCb.callCount, 2);
	t.is(onSuccess.callCount, 2);

	if (responed1) {
		t.is(responed1.url, '/users');
		t.is(responed1.url, responed2.url);
	}

	t.not(responed1, responed2);

});
開發者ID:niantuo,項目名稱:axios-extensions,代碼行數:25,代碼來源:test-cacheAdapterEnhancer.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: 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

示例5: get

 async get(key: string) {
   return this.store.get(key);
 }
開發者ID:apollostack,項目名稱:apollo-server,代碼行數:3,代碼來源:InMemoryLRUCache.ts

示例6: 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.get函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。