Module: MultiJSON::OptionsCache Private

Defined in:
lib/multi_json/options_cache.rb,
lib/multi_json/options_cache/mutex_store.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Thread-safe bounded cache for merged options hashes

Caches are separated for load and dump operations. Each cache is bounded to prevent unbounded memory growth when options are generated dynamically. The Store backend is chosen at load time based on RUBY_ENGINE: JRuby uses Concurrent::Map (shipped as a runtime dependency of the java-platform gem); MRI and TruffleRuby use a Hash guarded by a Mutex.

Defined Under Namespace

Classes: Store

Constant Summary collapse

DEFAULT_MAX_CACHE_SIZE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Default bound on the number of cached entries per store. Applications that dynamically generate many distinct option hashes can raise this via max_cache_size=.

1000

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.dumpStore (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the dump options cache

Returns:

  • (Store)

    dump cache store



32
33
34
# File 'lib/multi_json/options_cache.rb', line 32

def dump
  @dump
end

.loadStore (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the load options cache

Returns:

  • (Store)

    load cache store



38
39
40
# File 'lib/multi_json/options_cache.rb', line 38

def load
  @load
end

.max_cache_sizeInteger

Maximum number of entries per cache store

Applies to both the dump and load caches. Existing entries are left in place until normal eviction trims them below a lowered limit; call reset if you need to evict immediately.

Examples:

MultiJSON::OptionsCache.max_cache_size = 5000
MultiJSON::OptionsCache.max_cache_size  #=> 5000

Returns:

  • (Integer)

    current cache size limit



51
52
53
# File 'lib/multi_json/options_cache.rb', line 51

def max_cache_size
  @max_cache_size
end

Class Method Details

.resetvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Reset both caches



71
72
73
74
# File 'lib/multi_json/options_cache.rb', line 71

def reset
  @dump = Store.new
  @load = Store.new
end