Class: OpenBEL::Plugin::CacheKyotoCabinet
- Inherits:
-
Object
- Object
- OpenBEL::Plugin::CacheKyotoCabinet
show all
- Includes:
- OpenBEL::Plugin
- Defined in:
- lib/openbel/api/plugin/cache/kyotocabinet.rb
Constant Summary
collapse
- ID =
'kyotocabinet'
- NAME =
'KyotoCabinet Cache'
- DESC =
'Cache implementation using KyotoCabinet over FFI.'
- MEMR_TYPES =
[ :"memory-hash" ]
- FILE_TYPES =
[ :"file-hash" ]
- TYPE_OPTION_VALUES =
[ MEMR_TYPES, FILE_TYPES ].flatten
- MODE_OPTION_VALUES =
[ :reader, :writer, :create ]
- CREATE_MUTEX =
Mutex.new
EMPTY_ARRAY
Instance Method Summary
collapse
#<=>, #==, #hash, included, #on_unload, #optional_extensions, #required_extensions
Instance Method Details
59
60
61
|
# File 'lib/openbel/api/plugin/cache/kyotocabinet.rb', line 59
def configure(extensions = {}, options = {})
@options = options
end
|
#create_instance ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/openbel/api/plugin/cache/kyotocabinet.rb', line 63
def create_instance
CREATE_MUTEX.lock
begin
unless @instance
type = @options[:type].to_sym
mode = @options[:mode].map { |v| v.to_s.to_sym }
@instance = case type
when :"memory-hash"
KyotoCabinet::Db::MemoryHash.new mode
when :"file-hash"
KyotoCabinet::Db::PolymorphicDb::tmp_filedb(KyotoCabinet::FILE_HASH)
end
end
ensure
CREATE_MUTEX.unlock
end
@instance
end
|
#description ⇒ Object
28
29
30
|
# File 'lib/openbel/api/plugin/cache/kyotocabinet.rb', line 28
def description
DESC
end
|
#id ⇒ Object
20
21
22
|
# File 'lib/openbel/api/plugin/cache/kyotocabinet.rb', line 20
def id
ID
end
|
#name ⇒ Object
24
25
26
|
# File 'lib/openbel/api/plugin/cache/kyotocabinet.rb', line 24
def name
NAME
end
|
#on_load ⇒ Object
36
37
38
|
# File 'lib/openbel/api/plugin/cache/kyotocabinet.rb', line 36
def on_load
require 'kyotocabinet_ffi'
end
|
#type ⇒ Object
32
33
34
|
# File 'lib/openbel/api/plugin/cache/kyotocabinet.rb', line 32
def type
:cache
end
|
#validate(extensions = {}, options = {}) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/openbel/api/plugin/cache/kyotocabinet.rb', line 40
def validate(extensions = {}, options = {})
type = options.delete(:type)
if not type
return ValidationError.new(self, :type, "Option is missing. Options are one of [#{TYPE_OPTION_VALUES.join(', ')}].")
end
type = type.to_sym
if not TYPE_OPTION_VALUES.include?(type)
return ValidationError.new(self, :type, "Value not supported. Options are one of [#{TYPE_OPTION_VALUES.join(', ')}].")
end
mode = options.delete(:mode)
if not mode
return ValidationError.new(self, :mode, "Option is missing. Options are one of [#{MODE_OPTION_VALUES.join(', ')}].")
end
mode = mode.map { |v| v.to_s.to_sym }
validation_successful
end
|