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


TypeScript lru-cache類代碼示例

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


在下文中一共展示了lru-cache類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: require

/*
Use nteracts kernelspecs module to get data about all installed Jupyter kernels.

The result is cached for 5s to avoid wasted effort in case of a flurry of calls.

Specs: https://jupyter-client.readthedocs.io/en/stable/kernels.html#kernel-specs
*/

import { findAll } from "kernelspecs";

// const { findAll } = require("kernelspecs");
const { field_cmp } = require("smc-util/misc");
import * as LRU from "lru-cache";

const cache = LRU({ maxAge: 5000 });

export async function get_kernel_data(): Promise<any> {
  let kernel_data = cache.get("kernel_data");
  if (kernel_data != null) {
    return kernel_data;
  }
  const ks = await findAll();
  kernel_data = { kernelspecs: ks };
  const v: any[] = [];
  for (let kernel in kernel_data.kernelspecs) {
    const value = kernel_data.kernelspecs[kernel];
    v.push({
      name: kernel,
      display_name: value.spec.display_name,
      language: value.spec.language,
      interrupt_mode: value.spec.interrupt_mode,
開發者ID:DrXyzzy,項目名稱:smc,代碼行數:31,代碼來源:kernel-data.ts

示例2: katex_plugin

import * as LRU from "lru-cache";

const { macros } = require("../math_katex");

declare global {
  interface JQuery {
    katex(): JQuery;
  }
}

$.fn.katex = function() {
  this.each(katex_plugin);
  return this;
};

const math_cache = LRU({ max: CACHE_SIZE });

function katex_plugin(): void {
  const elt = $(this);

  // Run Mathjax's processor on this DOM node.
  // This puts any math it detects in nice script tags:
  //    <script type="math/tex">x^2</script>
  //    <script type="math/tex; mode=display">x^2</script>
  tex2jax.PreProcess(elt[0]);

  // Select all the math and try to use katex on each part.
  elt.find("script").each(function() {
    let node = $(this);
    if (
      (node[0] as any).type == "math/tex" ||
開發者ID:DrXyzzy,項目名稱:smc,代碼行數:31,代碼來源:katex.ts

示例3: constructor

    /**
     * Creates a new SQL-based matcher using the provided SQL client and the
     * given TTL for caching uses and channels.
     */
    constructor(cacheTTL: number = 60000) {
        this.discordToMixerChannelCache = cache({ maxAge: cacheTTL });
        this.mixerToDiscordChannelCache = cache({ maxAge: cacheTTL });
        this.discordToMixerUserCache = cache({ maxAge: cacheTTL });
        this.mixerUserCache = cache({ maxAge: cacheTTL });

        this.interval = setInterval(() => this.prune(), cacheTTL * 3 / 2);
    }
開發者ID:WatchBeam,項目名稱:discord-sync,代碼行數:12,代碼來源:matcher.ts

示例4: url_to_pdf

const options = {
  max: MAX_PAGES,
  length: function(doc: PDFDocumentProxy): number {
    return doc.numPages;
  }
};

export function url_to_pdf(
  project_id: string,
  path: string,
  reload: number
): string {
  return `${raw_url(project_id, encode_path(pdf_path(path)))}?param=${reload}`;
}

const doc_cache = LRU(options);

export const getDocument: (
  url: string
) => PDFPromise<PDFDocumentProxy> = reuseInFlight(async function(url) {
  let doc: PDFDocumentProxy | undefined = doc_cache.get(url);
  if (doc === undefined) {
    doc = await pdfjs_getDocument({
      url: url,
      disableStream: true,
      disableAutoFetch: true
    });
    doc_cache.set(url, doc);
  }
  return doc;
});
開發者ID:DrXyzzy,項目名稱:smc,代碼行數:31,代碼來源:pdfjs-doc-cache.ts

示例5: constructor

 // FIXME: Define reasonable default max size of the cache
 constructor({ maxSize = Infinity }: { maxSize?: number } = {}) {
   this.store = LRU({
     max: maxSize,
     length: item => item.length,
   });
 }
開發者ID:simonjoom,項目名稱:react-native-project,代碼行數:7,代碼來源:InMemoryLRUCache.ts


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