当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript lru_map.LRUMap类代码示例

本文整理汇总了TypeScript中lru_map.LRUMap的典型用法代码示例。如果您正苦于以下问题:TypeScript LRUMap类的具体用法?TypeScript LRUMap怎么用?TypeScript LRUMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LRUMap类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1:

function setRejected<I, V>(cache: LRUMap<I, Result<V>>, input: I, error: any) {
  const result = cache.get(input)

  if (result) {
    const newResult: RejectedResult = result as any

    newResult.status = REJECTED
    newResult.value = error
    return newResult
  } else {
    const newResult: RejectedResult = {
      status: REJECTED,
      value: error
    }

    cache.set(input, newResult)
    return newResult
  }
}
开发者ID:8th713,项目名称:cockpit-for-pixiv,代码行数:19,代码来源:useCache.ts

示例2: fetch

function accessResult<I, V>(
  cache: LRUMap<I, Result<V>>,
  fetch: (input: I) => Promise<V>,
  input: I
): Result<V> {
  let entry = cache.get(input)

  if (entry === undefined) {
    const thenable = fetch(input)

    thenable.then(
      value => {
        if (newResult.status === PENDING) {
          const resolvedResult: ResolvedResult<V> = newResult as any
          resolvedResult.status = RESOLVED
          resolvedResult.value = value
        }
      },
      error => {
        if (newResult.status === PENDING) {
          const rejectedResult: RejectedResult = newResult as any
          rejectedResult.status = REJECTED
          rejectedResult.value = error
        }
      }
    )

    const newResult: PendingResult = {
      status: PENDING,
      value: thenable
    }

    cache.set(input, newResult)
    return newResult
  } else {
    return entry
  }
}
开发者ID:8th713,项目名称:cockpit-for-pixiv,代码行数:38,代码来源:useCache.ts

示例3: remove

    function remove() {
      cache.delete(input)

      if (input !== inputRef.current) return

      forceUpdate()
    }
开发者ID:8th713,项目名称:cockpit-for-pixiv,代码行数:7,代码来源:useCache.ts

示例4: readFile

      readFile(filename, (err: Error | null, data: Buffer) => {
        const content = err ? null : data.toString();
        sourceFiles[filename] = content;

        // We always want to set the cache, even to null which means there was an error reading the file.
        // We do not want to try to read the file again.
        FILE_CONTENT_CACHE.set(filename, content);
        count++;
        if (count === filenames.length) {
          resolve(sourceFiles);
        }
      });
开发者ID:getsentry,项目名称:raven-js,代码行数:12,代码来源:parsers.ts

示例5: read

    function read() {
      const result = accessResult(cache, fetch, input)

      switch (result.status) {
        case PENDING: {
          throw result.value
        }
        case RESOLVED: {
          if (forceFetch) {
            cache.delete(input)
          }
          return result.value
        }
        case REJECTED: {
          if (forceFetch) {
            cache.delete(input)
          }

          throw result.value
        }
      }
    }
开发者ID:8th713,项目名称:cockpit-for-pixiv,代码行数:22,代码来源:useCache.ts

示例6: resolve

  }>(resolve => {
    const sourceFiles: {
      [key: string]: string | null;
    } = {};

    let count = 0;
    // tslint:disable-next-line:prefer-for-of
    for (let i = 0; i < filenames.length; i++) {
      const filename = filenames[i];

      const cache = FILE_CONTENT_CACHE.get(filename);
      // We have a cache hit
      if (cache !== undefined) {
        // If it's not null (which means we found a file and have a content)
        // we set the content and return it later.
        if (cache !== null) {
          sourceFiles[filename] = cache;
        }
        count++;
        // In any case we want to skip here then since we have a content already or we couldn't
        // read the file and don't want to try again.
        if (count === filenames.length) {
          resolve(sourceFiles);
        }
        continue;
      }

      readFile(filename, (err: Error | null, data: Buffer) => {
        const content = err ? null : data.toString();
        sourceFiles[filename] = content;

        // We always want to set the cache, even to null which means there was an error reading the file.
        // We do not want to try to read the file again.
        FILE_CONTENT_CACHE.set(filename, content);
        count++;
        if (count === filenames.length) {
          resolve(sourceFiles);
        }
      });
    }
  });
开发者ID:getsentry,项目名称:raven-js,代码行数:41,代码来源:parsers.ts

示例7: resetFileContentCache

export function resetFileContentCache(): void {
  FILE_CONTENT_CACHE.clear();
}
开发者ID:getsentry,项目名称:raven-js,代码行数:3,代码来源:parsers.ts


注:本文中的lru_map.LRUMap类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。