当前位置: 首页>>代码示例>>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;未经允许,请勿转载。