Class: TheArrayComparator::CachingStrategies::AnonymousCache

Inherits:
Object
  • Object
show all
Defined in:
lib/the_array_comparator/caching_strategies/anonymous_cache.rb

Overview

anonymous cache

Instance Method Summary collapse

Constructor Details

#initializeAnonymousCache

Create cache



11
12
13
14
# File 'lib/the_array_comparator/caching_strategies/anonymous_cache.rb', line 11

def initialize
  @cache = []
  @new_objects = false
end

Instance Method Details

#add(obj) ⇒ Object

Add object to cache

Parameters:

  • obj (Object)

    the object which should be added to the cache

Returns:

  • (Object)

    the object which has beed added



23
24
25
26
27
28
# File 'lib/the_array_comparator/caching_strategies/anonymous_cache.rb', line 23

def add(obj)
  @cache << obj
  @new_objects = true

  obj
end

#clearObject

Clear the cache (delete all objects)



40
41
42
# File 'lib/the_array_comparator/caching_strategies/anonymous_cache.rb', line 40

def clear
  @cache = []
end

#delete_object(num) ⇒ Object

Delete an object from cache by number

Returns:

  • the deleted object



56
57
58
# File 'lib/the_array_comparator/caching_strategies/anonymous_cache.rb', line 56

def delete_object(num)
  @cache.delete_at(num)
end

#fetch_object(num) ⇒ Object

Request an object from cache by number

Returns:

  • the requested object



64
65
66
# File 'lib/the_array_comparator/caching_strategies/anonymous_cache.rb', line 64

def fetch_object(num)
  @cache[num]
end

#new_objects?TrueClass, FalseClass

Are there new objects

Returns:

  • (TrueClass, FalseClass)

    the result of the check



48
49
50
# File 'lib/the_array_comparator/caching_strategies/anonymous_cache.rb', line 48

def new_objects?
  @new_objects
end

#stored_objectsArray

Return all stored objects

Returns:

  • (Array)

    the cache



34
35
36
37
# File 'lib/the_array_comparator/caching_strategies/anonymous_cache.rb', line 34

def stored_objects
  @new_objects = false
  @cache
end