Show:

Q.Cache Class

A Q.Cache object stores items in a cache and throws out least-recently-used ones.

Constructor

Q.Cache

(
  • options
)

Parameters:

  • options Object

    you can pass the following options:

    • [localStorage] Boolean optional

      use local storage instead of page storage

    • [sessionStorage] Boolean optional

      use session storage instead of page storage

    • [name] String optional

      the name of the cache, not really used for now

    • [max=100] Integer optional

      the maximum number of items the cache should hold. Defaults to 100.

    • [after] Q.Cache optional

      pass an existing cache with max > this cache's max, to look in first

Item Index

Methods

Methods

clear

() static

Accesses the cache and clears all entries from it

count

() Number

Returns the number of entries in the cache

Returns:

each

(
  • args
  • callback
)

Cycles through all the entries in the cache

Parameters:

  • args Array

    An array consisting of some or all the arguments that form the key

  • callback Function

    Is passed two parameters: key, value, with this = the cache

earliest

() String

Returns the key corresponding to the entry that was touched the earliest

Returns:

get

(
  • key
  • options
)
Mixed

Accesses the cache and gets an entry from it

Parameters:

  • key String

    the key to search for

  • options Object

    supports the following options:

    • [dontTouch=false] Boolean optional

      if true, then doesn't mark item as most recently used

Returns:

Mixed:

whatever is stored there, or else returns undefined

key

(
  • args
  • functions
)
String static

Generates the key under which things will be stored in a cache

Parameters:

  • args Array

    the arguments from which to generate the key

  • functions Array

    optional array to which all the functions found in the arguments will be pushed

Returns:

latest

() String

Returns the key corresponding to the entry that was touched the latest

Returns:

remove

(
  • key
)
Boolean static

Accesses the cache and removes an entry from it.

Parameters:

  • key String

    the key of the entry to remove

Returns:

Boolean:

whether there was an existing entry under that key

removeEach

(
  • args
)

Removes all the entries in the cache matching the args

Parameters:

  • args Array

    An array consisting of some or all the arguments that form the key

set

(
  • key
  • cbpos
  • subject
  • params
  • options
)
Boolean

Accesses the cache and sets an entry in it

Parameters:

  • key String

    the key to save the entry under, or an array of arguments

  • cbpos Number

    the position of the callback

  • subject Object

    The "this" object for the callback

  • params Array

    The parameters for the callback

  • options Object

    supports the following options:

    • [dontTouch=false] Boolean optional

      if true, then doesn't mark item as most recently used

Returns:

Boolean:

whether there was an existing entry under that key