當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。