Class: Moneta::Adapters::LRUHash

### Home Classes Methods

### In Files

- lib/moneta/adapters/lruhash.rb

### Parent

Object

### Namespace

- CLASS Moneta::Adapters::LRUHash::Entry

### Methods

- ::new
- #clear
- #delete
- #key?
- #load
- #store

### Included Modules

- Moneta::Defaults
- Moneta::IncrementSupport
- Moneta::CreateSupport

### Files

- LICENSE

### Class/Module Index

Quicksearch

- Moneta
- Moneta::Adapters
- Moneta::Adapters::ActiveRecord
- Moneta::Adapters::Cassandra
- Moneta::Adapters::Client
- Moneta::Adapters::Cookie
- Moneta::Adapters::Couch
- Moneta::Adapters::DBM
- Moneta::Adapters::DataMapper
- Moneta::Adapters::DataMapper::Store
- Moneta::Adapters::Daybreak
- Moneta::Adapters::File
- Moneta::Adapters::Fog
- Moneta::Adapters::GDBM
- Moneta::Adapters::HBase
- Moneta::Adapters::KyotoCabinet
- Moneta::Adapters::LMDB
- Moneta::Adapters::LRUHash
- Moneta::Adapters::LRUHash::Entry
- Moneta::Adapters::LevelDB
- Moneta::Adapters::LocalMemCache
- Moneta::Adapters::MemcachedDalli
- Moneta::Adapters::MemcachedNative
- Moneta::Adapters::Memory
- Moneta::Adapters::MongoBase
- Moneta::Adapters::MongoMoped
- Moneta::Adapters::MongoOfficial
- Moneta::Adapters::Null
- Moneta::Adapters::PStore
- Moneta::Adapters::Redis
- Moneta::Adapters::RestClient
- Moneta::Adapters::Riak
- Moneta::Adapters::SDBM
- Moneta::Adapters::Sequel
- Moneta::Adapters::Sqlite
- Moneta::Adapters::TDB
- Moneta::Adapters::TokyoCabinet
- Moneta::Adapters::TokyoTyrant
- Moneta::Adapters::YAML
- Moneta::Builder
- Moneta::Cache
- Moneta::Cache::DSL
- Moneta::CreateSupport
- Moneta::Defaults
- Moneta::Defaults::ClassMethods
- Moneta::Expires
- Moneta::ExpiresSupport
- Moneta::HashAdapter
- Moneta::IncrementSupport
- Moneta::Lock
- Moneta::Logger
- Moneta::Logger::Format
- Moneta::Mutex
- Moneta::OptionMerger
- Moneta::OptionSupport
- Moneta::Pool
- Moneta::Proxy
- Moneta::Semaphore
- Moneta::Server
- Moneta::Shared
- Moneta::Stack
- Moneta::Stack::DSL
- Moneta::SynchronizePrimitive
- Moneta::Transformer
- Moneta::Transformer::Helper
- Moneta::Utils
- Moneta::WeakCreate
- Moneta::WeakIncrement
- Moneta::Wrapper
- Rack
- Rack::Cache
- Rack::Cache::EntityStore
- Rack::Cache::EntityStore::MONETA
- Rack::Cache::EntityStore::Moneta
- Rack::Cache::MetaStore
- Rack::Cache::MetaStore::MONETA
- Rack::Cache::MetaStore::Moneta
- Rack::Cache::MonetaResolver
- Rack::MonetaCookies
- Rack::MonetaRest
- Rack::MonetaStore
- Rack::Session
- Rack::Session::Moneta
- ActionDispatch
- ActionDispatch::Session
- ActionDispatch::Session::MonetaStore
- ActiveSupport
- ActiveSupport::Cache
- ActiveSupport::Cache::MonetaStore

No matching classes.

# Moneta::Adapters::LRUHash

LRUHash backend

Based on Hashery::LRUHash but simpler and measures both memory usage and hash size.

@api public

### Public Class Methods

new(options = {}) click to toggle source

@param [Hash] options @option options [Integer] :max_size (1024000) Maximum byte size of all values @option options [Integer] :max_value (options) Maximum byte size of one value @option options [Integer] :max_count (10240) Maximum number of values

    # File lib/moneta/adapters/lruhash.rb, line 17
    def initialize(options = {})
      @max_size = options[:max_size] || 1024000
      @max_count = options[:max_count] || 10240
      @max_value = options[:max_value] || @max_size
      clear
    end

### Public Instance Methods

clear(options = {}) click to toggle source

(see Proxy#clear)

    # File lib/moneta/adapters/lruhash.rb, line 66
    def clear(options = {})
      @entry, @size = {}, 0
      @list = Entry.new
      @list.prev = @list.next = @list
      self
    end

delete(key, options = {}) click to toggle source

(see Proxy#delete)

    # File lib/moneta/adapters/lruhash.rb, line 57
    def delete(key, options = {})
      if entry = @entry.delete(key)
        @size -= entry.value.bytesize
        entry.unlink
        entry.value
      end
    end

key?(key, options = {}) click to toggle source

(see Proxy#key?)

    # File lib/moneta/adapters/lruhash.rb, line 25
    def key?(key, options = {})
      @entry.key?(key)
    end

load(key, options = {}) click to toggle source

(see Proxy#load)

    # File lib/moneta/adapters/lruhash.rb, line 30
    def load(key, options = {})
      if entry = @entry[key]
        entry.insert_after(@list)
        entry.value
      end
    end

store(key, value, options = {}) click to toggle source

(see Proxy#store)

    # File lib/moneta/adapters/lruhash.rb, line 38
    def store(key, value, options = {})
      if value.bytesize > @max_value
        delete(key)
      else
        if entry = @entry[key]
          @size -= entry.value.bytesize
        else
          @entry[key] = entry = Entry.new
          entry.key = key
        end
        entry.value = value
        @size += entry.value.bytesize
        entry.insert_after(@list)
        delete(@list.prev.key) while @list.next != @list.prev && (@size > @max_size || @entry.size > @max_count)
      end
      value
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.