How to use lru_map - 10 common examples

To help you get started, we’ve selected a few lru_map examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gocd / gocd / server / webapp / WEB-INF / rails / webpack / helpers / time_formatter.ts View on Github external
const CACHE_SIZE         = 10000;
const DATE_FORMAT        = "DD MMM YYYY";
const LOCAL_TIME_FORMAT  = "DD MMM, YYYY [at] HH:mm:ss [Local Time]";
const SERVER_TIME_FORMAT = "DD MMM, YYYY [at] HH:mm:ss Z [Server Time]";
// the default timestamp format rendered by the server
const defaultFormat      = "YYYY-MM-DDTHH:mm:ssZ";

const format = _.memoize((time) => {
  return moment(time, defaultFormat).format(LOCAL_TIME_FORMAT);
});
format.cache = new LRUMap(CACHE_SIZE);

const formatInServerTime = _.memoize((time) => {
  return moment(time, defaultFormat).utcOffset(utcOffsetInMinutes).format(SERVER_TIME_FORMAT);
});
formatInServerTime.cache = new LRUMap(CACHE_SIZE);

const formatInDate = (time?: moment.MomentInput) => {
  return moment(time, defaultFormat).format(DATE_FORMAT);
};

const toDate = (time?: moment.MomentInput) => {
  return moment(time, defaultFormat).toDate();
};

export const timeFormatter = {
  format,
  toDate,
  formatInDate,
  formatInServerTime
};
github gocd / gocd / server / webapp / WEB-INF / rails.new / webpack / helpers / time_formatter.js View on Github external
const LRUMap = require('lru_map').LRUMap;
require("moment-duration-format");

const utcOffsetInMinutes = parseInt(CONSTANTS.SERVER_TIMEZONE_UTC_OFFSET) / 60000;
const CACHE_SIZE         = 10000;
const DATE_FORMAT        = 'DD MMM YYYY';
const LOCAL_TIME_FORMAT  = 'DD MMM, YYYY [at] HH:mm:ss [Local Time]';
const SERVER_TIME_FORMAT = 'DD MMM, YYYY [at] HH:mm:ss Z [Server Time]';
// the default timestamp format rendered by the server
const defaultFormat      = 'YYYY-MM-DDTHH:mm:ssZ';

const format = _.memoize((time) => {
  return moment(time, defaultFormat).format(LOCAL_TIME_FORMAT);
});
format.cache = new LRUMap(CACHE_SIZE);

const formatInServerTime = _.memoize((time) => {
  return moment(time, defaultFormat).utcOffset(utcOffsetInMinutes).format(SERVER_TIME_FORMAT);
});
formatInServerTime.cache = new LRUMap(CACHE_SIZE);

const formatInDate = (time) => {
  return moment(time, defaultFormat).format(DATE_FORMAT);
};

module.exports = {
  format,
  formatInDate,
  formatInServerTime
};
github liaisonjs / liaison / packages / storable / src / cache.js View on Github external
import {FieldMask} from '@liaison/model';
import LRUMapModule from 'lru_map';
const LRUMap = LRUMapModule.LRUMap; // Turn around an issue when bundling with Rollup

/* eslint-disable guard-for-in */

export class Cache {
  constructor(parent, {size}) {
    this._parent = parent;
    this._size = size;

    this._entries = new LRUMap(size);
    this._entries.shift = () => {
      // Delete indexes when an entry is evicted from the cache
      const entry = LRUMap.prototype.shift.call(this._entries);
      this._deleteIndexes(entry.indexedFields);
      return entry;
    };
github rangle / angular-ssr / source / cache / memory-variant-cache.ts View on Github external
constructor(
    private application: Application<V>,
    private cacheSize = 1 << 16,
    private ttl = 1 << 18
  ) {
    this.cache = new LRUMap<string, Trie<V, Pair<V>>>(this.cacheSize);
  }
github rgraphql / soyuz / src / result-tree / path-cache.ts View on Github external
constructor(size: number, evictCb: PathCacheEvictHandler | null) {
    this.evictCb = evictCb
    this.cache = new LRUMap<number, PathCursor>(size)
  }
github polkadot-js / common / packages / db / src / FileFlatDb / Cache.ts View on Github external
constructor (base: string, file: string, options: BaseDbOptions) {
    super(base, file, options);

    this._lruBranch = new LRUMap(defaults.LRU_BRANCH_COUNT);
    this._lruData = new LRUMap(defaults.LRU_DATA_COUNT);
  }
github polkadot-js / common / packages / db / src / engines / LruDb.ts View on Github external
constructor (backing: BaseDb, itemCount: number = DEFAULT_ITEM_COUNT) {
    this.backing = backing;
    this.lru = new LRUMap(itemCount);
  }
github 8th713 / cockpit-for-pixiv / packages / core / externals / apiClient.ts View on Github external
const parsedText = JSON.parse(text.slice(21, -1))
    const userTags: AccountTagList = JSON.parse(parsedText)

    return Object.entries(userTags).map(([name, value]) => ({
      ...value,
      name
    }))
  }

  const usePageCache = createCacheHook(fetchPages, new LRUMap(20))
  const useUgoiraCache = createCacheHook(fetchUgoira, new LRUMap(1))
  const useIllustCache = createCacheHook(fetchIllust, new LRUMap(20))
  const useUserCache = createCacheHook(fetchUser, new LRUMap(20))
  const useBookmarkCache = createCacheHook(
    fetchBookmarkForm,
    new LRUMap(1),
    true
  )

  return {
    token,
    yourId,
    isSelf,
    usePageCache,
    fetchImage,
    useUgoiraCache,
    useIllustCache,
    likeBy,
    bookmarkBy,
    useUserCache,
    followUser,
    useBookmarkCache
github rangle / angular-ssr / source / store / document-store.ts View on Github external
constructor(private application: Application<any, M>, cacheSize = defaultCacheSize) {
    this.cache = new LRUMap<string, Snapshot<void>>(cacheSize);
  }
github atomist / automation-client / lib / internal / event / InMemoryEventStore.ts View on Github external
constructor() {
        this.eventCache = new LRUMap<CacheKey, EventIncoming>(100);
        this.commandCache = new LRUMap<CacheKey, CommandIncoming>(100);
        this.messageCache = new LRUMap<CacheKey, any>(100);
    }

lru_map

Finite key-value map using the Least Recently Used (LRU) algorithm where the most recently used objects are keept in the map while less recently used items are evicted to make room for new ones.

MIT
Latest version published 2 years ago

Package Health Score

67 / 100
Full package analysis

Popular lru_map functions