本文整理汇总了TypeScript中lru-cache.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript lru-cache.default方法的具体用法?TypeScript lru-cache.default怎么用?TypeScript lru-cache.default使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lru-cache
的用法示例。
在下文中一共展示了lru-cache.default方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
// FIXME: Define reasonable default max size of the cache
constructor({ maxSize = Infinity }: { maxSize?: number } = {}) {
this.store = LRU({
max: maxSize,
length: item => item.length,
});
}
示例2: 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);
}
示例3: 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,
示例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;
});
示例5: 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" ||