Class: Sprockets::Cache::MemoryStore

### Home Classes Methods

### In Files

- lib/sprockets/cache/memory_store.rb

### Parent

Object

### Methods

- ::new
- #get
- #inspect
- #set

### Class/Module Index

Quicksearch

- Sprockets
- Sprockets::ArgumentError
- Sprockets::Asset
- Sprockets::Autoload
- Sprockets::Base
- Sprockets::Bower
- Sprockets::Bundle
- Sprockets::Cache
- Sprockets::Cache::FileStore
- Sprockets::Cache::GetWrapper
- Sprockets::Cache::HashWrapper
- Sprockets::Cache::MemoryStore
- Sprockets::Cache::NullStore
- Sprockets::Cache::ReadWriteWrapper
- Sprockets::Cache::Wrapper
- Sprockets::CachedEnvironment
- Sprockets::ClosureCompressor
- Sprockets::CoffeeScriptProcessor
- Sprockets::CoffeeScriptTemplate
- Sprockets::Compressing
- Sprockets::Configuration
- Sprockets::ContentTypeMismatch
- Sprockets::Context
- Sprockets::ConversionError
- Sprockets::Dependencies
- Sprockets::DigestUtils
- Sprockets::DirectiveProcessor
- Sprockets::ERBProcessor
- Sprockets::ERBTemplate
- Sprockets::EcoProcessor
- Sprockets::EcoTemplate
- Sprockets::EjsProcessor
- Sprockets::EjsTemplate
- Sprockets::EncodingUtils
- Sprockets::Engines
- Sprockets::Environment
- Sprockets::Error
- Sprockets::FileNotFound
- Sprockets::FileOutsidePaths
- Sprockets::FileReader
- Sprockets::HTTPUtils
- Sprockets::Index
- Sprockets::JstProcessor
- Sprockets::LegacyProcProcessor
- Sprockets::LegacyTiltProcessor
- Sprockets::Loader
- Sprockets::Manifest
- Sprockets::ManifestUtils
- Sprockets::Mime
- Sprockets::NotFound
- Sprockets::NotImplementedError
- Sprockets::PathDependencyUtils
- Sprockets::PathDigestUtils
- Sprockets::PathUtils
- Sprockets::Paths
- Sprockets::Processing
- Sprockets::ProcessorUtils
- Sprockets::Resolve
- Sprockets::SassCompressor
- Sprockets::SassProcessor
- Sprockets::SassProcessor::CacheStore
- Sprockets::SassProcessor::Functions
- Sprockets::SassTemplate
- Sprockets::ScssProcessor
- Sprockets::ScssTemplate
- Sprockets::Server
- Sprockets::Transformers
- Sprockets::URITar
- Sprockets::URIUtils
- Sprockets::UglifierCompressor
- Sprockets::UnloadedAsset
- Sprockets::Utils
- Sprockets::YUICompressor
- Rake
- Rake::SprocketsTask

No matching classes.

# Sprockets::Cache::MemoryStore

Public: Basic in memory LRU cache.

Assign the instance to the Environment#cache.

    environment.cache = Sprockets::Cache::MemoryStore.new(1000)

See Also

    ActiveSupport::Cache::MemoryStore

### Constants

DEFAULT_MAX_SIZE

  Internal: Default key limit for store.

### Public Class Methods

new(max_size = DEFAULT_MAX_SIZE) click to toggle source

Public: Initialize the cache store.

max_size - A Integer of the maximum number of keys the store will hold.

    (default: 1000).

    # File lib/sprockets/cache/memory_store.rb, line 21
    def initialize(max_size = DEFAULT_MAX_SIZE)
      @max_size = max_size
      @cache = {}
    end

### Public Instance Methods

get(key) click to toggle source

Public: Retrieve value from cache.

This API should not be used directly, but via the Cache wrapper API.

key - String cache key.

Returns Object or nil or the value is not set.

    # File lib/sprockets/cache/memory_store.rb, line 33
    def get(key)
      exists = true
      value = @cache.delete(key) { exists = false }
      if exists
        @cache[key] = value
      else
        nil
      end
    end

inspect() click to toggle source

Public: Pretty inspect

Returns String.

    # File lib/sprockets/cache/memory_store.rb, line 61
    def inspect
      "#<#{self.class} size=#{@cache.size}/#{@max_size}>"
    end

set(key, value) click to toggle source

Public: Set a key and value in the cache.

This API should not be used directly, but via the Cache wrapper API.

key - String cache key. value - Object value.

Returns Object value.

    # File lib/sprockets/cache/memory_store.rb, line 51
    def set(key, value)
      @cache.delete(key)
      @cache[key] = value
      @cache.shift if @cache.size > @max_size
      value
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.