Class: Moon::CacheBase

Inherits:
Object show all
Defined in:
lib/moon/packages/std/cache_base.rb

Overview

General purspose cache. Simply create new branches (loaders) and the cache will do the rest.

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ CacheBase

Returns a new instance of CacheBase.

Parameters:

  • name (String) (defaults to: nil)

6
7
8
9
10
11
# File 'lib/moon/packages/std/cache_base.rb', line 6

def initialize(name = nil)
  @name = name || self.class.to_s
  @cache = {}

  post_initialize
end

Instance Method Details

#clear(branch_name = nil) ⇒ Void

Returns:

  • (Void)

25
26
27
28
29
30
31
32
33
# File 'lib/moon/packages/std/cache_base.rb', line 25

def clear(branch_name = nil)
  if branch_name
    if cache = @cache[branch_name]
      cache.clear
    end
  else
    @cache.clear
  end
end

#debug({ |io| do_with_io }) ⇒ Void

Yields:

  • (STDERR)

Returns:

  • (Void)

20
21
22
# File 'lib/moon/packages/std/cache_base.rb', line 20

def debug
  yield STDERR
end

#entries(branch_name) ⇒ Object

Parameters:


36
37
38
# File 'lib/moon/packages/std/cache_base.rb', line 36

def entries(branch_name)
  @cache[branch_name] || {}
end

#post_initializeObject

Hook function called at the end of initialize


14
15
16
# File 'lib/moon/packages/std/cache_base.rb', line 14

def post_initialize  #

end