Class: GameMachine::GCache::Cache

Inherits:
Object
  • Object
show all
Defined in:
server/lib/game_machine/gcache/cache.rb

Defined Under Namespace

Classes: CallableImpl, ObjectWrapper

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(delegate) ⇒ Cache

Returns a new instance of Cache


20
21
22
# File 'server/lib/game_machine/gcache/cache.rb', line 20

def initialize(delegate)
  @delegate = delegate
end

Class Method Details

.create(opts = Hash.new) ⇒ Object


7
8
9
10
11
12
13
14
15
16
# File 'server/lib/game_machine/gcache/cache.rb', line 7

def self.create(opts = Hash.new)
  cache_builder = JavaLib::CacheBuilder.new_builder
  cache_builder = cache_builder.maximum_size(opts[:maximum_size]) if opts.has_key?(:maximum_size)
  cache_builder = cache_builder.initial_capacity(opts[:initial_capacity]) if opts.has_key?(:initial_capacity)
  cache_builder = cache_builder.concurrency_level(opts[:concurrency_level]) if opts.has_key?(:concurrency_level)
  cache_builder = cache_builder.expire_after_write(opts[:expire_after_write_sec], java.util.concurrent.TimeUnit::SECONDS) if opts.has_key?(:expire_after_write_sec)
  cache_builder = cache_builder.expire_after_access(opts[:expire_after_access_sec], java.util.concurrent.TimeUnit::SECONDS) if opts.has_key?(:expire_after_access_sec)
  cache_builder = cache_builder.record_stats if opts.has_key?(:record_stats) && opts[:record_stats] == true
  new(cache_builder.build)
end

Instance Method Details

#get(key, &value_loader) ⇒ Object


24
25
26
27
# File 'server/lib/game_machine/gcache/cache.rb', line 24

def get(key, &value_loader)
  value = @delegate.get(ObjectWrapper.new(key), CallableImpl.new(value_loader))
  value == nil ? nil : value.wrapped_object
end

#get_if_present(key) ⇒ Object


29
30
31
32
# File 'server/lib/game_machine/gcache/cache.rb', line 29

def get_if_present(key)
  value = @delegate.get_if_present(ObjectWrapper.new(key))
  value == nil ? nil : value.wrapped_object
end

#invalidate(key) ⇒ Object


34
35
36
# File 'server/lib/game_machine/gcache/cache.rb', line 34

def invalidate(key)
  @delegate.invalidate(ObjectWrapper.new(key))
end

#invalidate_allObject


38
39
40
# File 'server/lib/game_machine/gcache/cache.rb', line 38

def invalidate_all
  @delegate.invalidate_all
end

#put(key, value) ⇒ Object


42
43
44
# File 'server/lib/game_machine/gcache/cache.rb', line 42

def put(key, value)
  @delegate.put(ObjectWrapper.new(key), ObjectWrapper.new(value))
end

#sizeObject


46
47
48
# File 'server/lib/game_machine/gcache/cache.rb', line 46

def size
  @delegate.size
end

#statsObject


50
51
52
# File 'server/lib/game_machine/gcache/cache.rb', line 50

def stats
  CacheStats.new(@delegate.stats)
end