Example #1
0
    /**
     * 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);
    }
Example #2
0
/*
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,
Example #3
0
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;
});
 // FIXME: Define reasonable default max size of the cache
 constructor({ maxSize = Infinity }: { maxSize?: number } = {}) {
   this.store = LRU({
     max: maxSize,
     length: item => item.length,
   });
 }
Example #5
0
File: katex.ts Project: DrXyzzy/smc
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" ||