Class: ThreadSafe::NonConcurrentCacheBackend

### Home Classes Methods

### In Files

- lib/thread_safe/non_concurrent_cache_backend.rb

### Parent

Object

### Methods

- ::new
- #[]
- #[]=
- #clear
- #compute
- #compute_if_absent
- #compute_if_present
- #delete
- #delete_pair
- #each_pair
- #get_and_set
- #get_or_default
- #key?
- #merge_pair
- #replace_if_exists
- #replace_pair
- #size
- #value?

### Class/Module Index

Quicksearch

- ThreadSafe
- ThreadSafe::Array
- ThreadSafe::AtomicReferenceCacheBackend
- ThreadSafe::AtomicReferenceCacheBackend::Node
- ThreadSafe::AtomicReferenceCacheBackend::Table
- ThreadSafe::Cache
- ThreadSafe::Hash
- ThreadSafe::MriCacheBackend
- ThreadSafe::NonConcurrentCacheBackend
- ThreadSafe::SynchronizedCacheBackend
- ThreadSafe::Util
- ThreadSafe::Util::Adder
- ThreadSafe::Util::CheapLockable
- ThreadSafe::Util::PowerOfTwoTuple
- ThreadSafe::Util::Striped64
- ThreadSafe::Util::Striped64::Cell
- ThreadSafe::Util::Volatile
- ThreadSafe::Util::VolatileTuple
- SynchronizedDelegator
- Threadsafe

No matching classes.

# ThreadSafe::NonConcurrentCacheBackend

### Public Class Methods

new(options = nil) click to toggle source

WARNING: all public methods of the class must operate on the @backend directly without calling each other. This is important because of the SynchronizedCacheBackend which uses a non-reentrant mutex for perfomance reasons.

    # File lib/thread_safe/non_concurrent_cache_backend.rb, line 7
    def initialize(options = nil)
      @backend = {}
    end

### Public Instance Methods

[](key) click to toggle source

    # File lib/thread_safe/non_concurrent_cache_backend.rb, line 11
    def [](key)
      @backend[key]
    end

Also aliased as: _get
[]=(key, value) click to toggle source

    # File lib/thread_safe/non_concurrent_cache_backend.rb, line 15
    def []=(key, value)
      @backend[key] = value
    end

Also aliased as: _set
clear() click to toggle source

    # File lib/thread_safe/non_concurrent_cache_backend.rb, line 88
    def clear
      @backend.clear
      self
    end

compute(key) click to toggle source

    # File lib/thread_safe/non_concurrent_cache_backend.rb, line 49
    def compute(key)
      store_computed_value(key, yield(@backend[key]))
    end

compute_if_absent(key) click to toggle source

    # File lib/thread_safe/non_concurrent_cache_backend.rb, line 19
    def compute_if_absent(key)
      if NULL != (stored_value = @backend.fetch(key, NULL))
        stored_value
      else
        @backend[key] = yield
      end
    end

compute_if_present(key) click to toggle source

    # File lib/thread_safe/non_concurrent_cache_backend.rb, line 43
    def compute_if_present(key)
      if NULL != (stored_value = @backend.fetch(key, NULL))
        store_computed_value(key, yield(stored_value))
      end
    end

delete(key) click to toggle source

    # File lib/thread_safe/non_concurrent_cache_backend.rb, line 75
    def delete(key)
      @backend.delete(key)
    end

delete_pair(key, value) click to toggle source

    # File lib/thread_safe/non_concurrent_cache_backend.rb, line 79
    def delete_pair(key, value)
      if pair?(key, value)
        @backend.delete(key)
        true
      else
        false
      end
    end

each_pair() click to toggle source

    # File lib/thread_safe/non_concurrent_cache_backend.rb, line 93
    def each_pair
      dupped_backend.each_pair do |k, v|
        yield k, v
      end
      self
    end

get_and_set(key, value) click to toggle source

    # File lib/thread_safe/non_concurrent_cache_backend.rb, line 61
    def get_and_set(key, value)
      stored_value = @backend[key]
      @backend[key] = value
      stored_value
    end

get_or_default(key, default_value) click to toggle source

    # File lib/thread_safe/non_concurrent_cache_backend.rb, line 104
    def get_or_default(key, default_value)
      @backend.fetch(key, default_value)
    end

key?(key) click to toggle source

    # File lib/thread_safe/non_concurrent_cache_backend.rb, line 67
    def key?(key)
      @backend.key?(key)
    end

merge_pair(key, value) click to toggle source

    # File lib/thread_safe/non_concurrent_cache_backend.rb, line 53
    def merge_pair(key, value)
      if NULL == (stored_value = @backend.fetch(key, NULL))
        @backend[key] = value
      else
        store_computed_value(key, yield(stored_value))
      end
    end

replace_if_exists(key, new_value) click to toggle source

    # File lib/thread_safe/non_concurrent_cache_backend.rb, line 36
    def replace_if_exists(key, new_value)
      if NULL != (stored_value = @backend.fetch(key, NULL))
        @backend[key] = new_value
        stored_value
      end
    end

replace_pair(key, old_value, new_value) click to toggle source

    # File lib/thread_safe/non_concurrent_cache_backend.rb, line 27
    def replace_pair(key, old_value, new_value)
      if pair?(key, old_value)
        @backend[key] = new_value
        true
      else
        false
      end
    end

size() click to toggle source

    # File lib/thread_safe/non_concurrent_cache_backend.rb, line 100
    def size
      @backend.size
    end

value?(value) click to toggle source

    # File lib/thread_safe/non_concurrent_cache_backend.rb, line 71
    def value?(value)
      @backend.value?(value)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.