Sha256: eefaa79821076d7a812214a3c1828a8322631965232f9db77e24291519900a24

Contents?: true

Size: 918 Bytes

Versions: 6

Compression:

Stored size: 918 Bytes

Contents

# A generic cache.
# Stores key-value pairs.
class window.modularity.Cache

  constructor: ->
    @cache = {}


  # Adds the given entry to the cache.
  # Overwrites existing entries.
  add: (key, value) ->
    @cache[key] = value


  # Returns the entry with the given key from the cache, or NULL if no entry exists.
  get: (key) ->
    @cache[key]


  # Looks up several entries at once.
  # Returns a hash of found entries, and a list of missing entries.
  getMany: (keys) ->
    result = { found: {}, missing: [] }
    for key in keys
      do (key) =>
        value = @cache[key]
        if value
          result.found[key] = value
        else
          result.missing.push key
    result


  # Replaces the cache with the given data.
  replaceAll: (data) ->
    @cache = data


  # Returns the number of cached objects.
  length: () ->
    # TODO(KG): This doesn't work in IE8.
    Object.keys(@cache).length

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
modularity-rails-0.10.0 vendor/assets/javascripts/modularity/tools/cache.coffee
modularity-rails-0.9.3 vendor/assets/javascripts/tools/cache.coffee
modularity-rails-0.9.2 vendor/assets/javascripts/tools/cache.coffee
modularity-rails-0.9.1 vendor/assets/javascripts/tools/cache.coffee
modularity-rails-0.9.0 vendor/assets/javascripts/tools/cache.coffee
modularity-rails-0.8.1 vendor/assets/javascripts/tools/cache.coffee