gis-tools-ts - v0.6.0
    Preparing search index...

    Class Cache<K, V>

    Cache System

    A cache of values with a max size to ensure that too much old data is not stored. The deletion system uses the FIFO policy

    import { Cache } from 'gis-tools-ts';

    const onDelete = (key: string, value: string) => {
    console.log(`Deleted key ${key} with value ${value}`);
    };
    const cache = new Cache<string, string>(10, onDelete);
    cache.set('key', 'value');
    console.log(cache.get('key')); // 'value'
    cache.delete('key');

    Type Parameters

    • K
    • V

    Hierarchy

    • Map<K, V>
      • Cache
    Index

    Constructors

    Methods

    Constructors

    • Type Parameters

      • K
      • V

      Parameters

      • maxSize: number

        the max size of the cache before dumping old data

      • OptionalonDelete: (key: K, value: V) => void

        if provided, will be called when a value is removed

      Returns Cache<K, V>

    Methods

    • Parameters

      • key: K

        the offset position in the data

      Returns boolean

      • true if found
    • Parameters

      • key: K

        the offset position in the data

      Returns undefined | V

      • the value if found
    • Parameters

      • key: K

        the offset position in the data

      • value: V

        the value to store

      Returns this

      this