Class FetchedIntervalCache<EntryType, N>

A set of distinct (non-intersecting) IntegerIntervals, each containing sorted, unique data. Each interval corresponds to one or more queries to a backend database.

Type Parameters

Hierarchy

  • FetchedIntervalCache

Constructors

  • Constructs a new, empty FetchedIntervalCache. Entries will be sorted by the sortKey provided. This function requires an IntervalFactory, while makeCache() provides a default one that should be sufficient in most cases.

    Type Parameters

    Parameters

    Returns FetchedIntervalCache<EntryType, N>

Properties

_intervalFactory: IntervalFactory<N>
_intervals: _FetchedInterval<EntryType, N>[]
_listeners: {
    callback: IntervalDataCallback<EntryType, N>;
    interval: IntegerInterval<N>;
}[]

Type declaration

_sortKey: IsValidAttribute<EntryType, N>

Methods

  • Iterates through the _FetchedIntervals and the empty intervals between _FetchedIntervals in the cache from iterationInterval.from to iterationInterval.to.

    Parameters

    • iterationInterval: IntegerInterval<N>
    • actions: {
          betweenIntervals: ((emptyInterval) => void);
          inInterval: ((entriesInterval) => void);
      }
      • betweenIntervals: ((emptyInterval) => void)
          • (emptyInterval): void
          • Parameters

            Returns void

      • inInterval: ((entriesInterval) => void)
          • (entriesInterval): void
          • Parameters

            • entriesInterval: _FetchedInterval<EntryType, N>

            Returns void

    Returns void

  • Attempts to add the entry to the cache. createInterval indicates if a new interval will be created if an appropriate one does not already exist. Returns true if the entry is added, and false otherwise (including if another entry with the same sort key value already exists). Appropriate callback(s) are invoked if the entry is added.

    Parameters

    • entry: Immutable<EntryType>
    • createInterval: boolean = false

    Returns boolean

  • "Subscribes" the callback function to the interval, such that the callback will be invoked whenever there are changes to the interval. Throws an error if the callback provided is already subscribed to an interval.

    Parameters

    Returns void

  • Returns the entries in the provided interval, as well as the intervals that are not in the cache (these should be subsequently fetched from the backend, so that the requested interval can be completely filled in).

    Parameters

    Returns IntervalData<EntryType, N>

  • Get the entry with a sort value greater than or equal to the value provided. Returns a missingInterval if an appropriate entry is not found in the cache, but could exist. Returns the entry if it is found. Returns noValue if all possible intervals have been fetched, and no appropriate entry exists.

    Parameters

    Returns SubsequentEntryData<EntryType, N>

  • Get the entry with a sort value less than or equal to the value provided. Returns a missingInterval if an appropriate entry is not found in the cache, but could exist. Returns the entry if it is found. Returns noValue if all possible intervals have been fetched, and no appropriate entry exists.

    Parameters

    Returns SubsequentEntryData<EntryType, N>

  • Adds a new interval of entries to the cache. Overlapping parts of existing intervals will be overwritten. Throws an error if entries are not sorted ascending by sort key, or if any of the entries have a duplicate sort value, or if any of the entries have a sort value outside of the insertInterval. Appropriate callback(s) are invoked.

    Parameters

    Returns void

  • Minifies this cache, so that it is smaller for JSON.stringify() or database insertion.

    Parameters

    Returns {
        e: any[];
        f: number;
        t: number;
    }[]

  • "Unsubscribes" the given callback function. Returns true if the given callback was "subscribed" to an inteval, and false otherwise.

    Parameters

    Returns boolean

  • Updates the entry if it exists in the cache. Returns the old entry if it existed, and null otherwise. Appropriate callback(s) are invoked if the entry is updated.

    Parameters

    Returns null | Immutable<EntryType>

  • Constructs a FetchedIntervalCache from a minified value. entryUnminifier should throw an error if passed a malformed or invalid minified entry.

    Type Parameters

    Parameters

    • sortKey: IsValidAttribute<EntryType, N>
    • entryUnminifier: Unminifier<EntryType>
    • intervalFactory: IntervalFactory<N>
    • minified: any

    Returns FetchedIntervalCache<EntryType, N>

Generated using TypeDoc