Class: Transit::RollingCache Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/transit/rolling_cache.rb

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

Constant Summary collapse

FIRST_ORD =

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.

48
LAST_ORD =

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.

91
CACHE_CODE_DIGITS =

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.

44
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.

CACHE_CODE_DIGITS * CACHE_CODE_DIGITS
MIN_SIZE_CACHEABLE =

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.

4

Instance Method Summary collapse

Constructor Details

#initializeRollingCache

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.

Returns a new instance of RollingCache.



28
29
30
# File 'lib/transit/rolling_cache.rb', line 28

def initialize
  clear
end

Instance Method Details

#cache_key?(str, _ = false) ⇒ Boolean

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.

Returns:

  • (Boolean)


45
46
47
# File 'lib/transit/rolling_cache.rb', line 45

def cache_key?(str, _=false)
  str[0] == SUB && str != MAP_AS_ARRAY
end

#cacheable?(str, as_map_key = false) ⇒ Boolean

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.

Returns:

  • (Boolean)


49
50
51
# File 'lib/transit/rolling_cache.rb', line 49

def cacheable?(str, as_map_key=false)
  str.size >= MIN_SIZE_CACHEABLE && (as_map_key || str.start_with?("~#","~$","~:"))
end

#read(key) ⇒ Object

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.



32
33
34
# File 'lib/transit/rolling_cache.rb', line 32

def read(key)
  @key_to_value[key]
end

#write(val) ⇒ Object

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.



36
37
38
39
40
41
42
43
# File 'lib/transit/rolling_cache.rb', line 36

def write(val)
  @value_to_key[val] || begin
                          clear if @key_to_value.size >= CACHE_SIZE
                          key = next_key(@key_to_value.size)
                          @value_to_key[val] = key
                          @key_to_value[key] = val
                        end
end