Weakhash: self cleaning cache. SBDB::Env#new: Hash-options added
This commit is contained in:
parent
bddc461ca4
commit
a4d1031d93
|
@ -54,7 +54,8 @@ module SBDB
|
|||
@home, @db = opts[:env], opts[:env] ? opts[:env].bdb_object.db : Bdb::Db.new
|
||||
opts[:type] = TYPES.index(self.class) || UNKNOWN
|
||||
@db.re_len = opts[:re_len] if opts[:re_len]
|
||||
begin @db.open opts[:txn], file, opts[:name], opts[:type], opts[:flags] || 0, opts[:mode] || 0
|
||||
begin
|
||||
@db.open opts[:txn], file, opts[:name], opts[:type], opts[:flags] || 0, opts[:mode] || 0
|
||||
rescue Object
|
||||
close
|
||||
raise $!
|
||||
|
|
|
@ -41,9 +41,18 @@ module SBDB
|
|||
open Unknown, file, *p, &e
|
||||
end
|
||||
|
||||
def initialize dir = nil, flags = nil, mode = nil
|
||||
# args:
|
||||
# args[0] => dir
|
||||
# args[1] => flags
|
||||
# args[3] => mode
|
||||
# possible options (via Hash):
|
||||
# :dir, :flags, :mode, :log_config
|
||||
def initialize *args
|
||||
opts = ::Hash === args.last ? args.pop : {}
|
||||
opts = {:dir => args[0], :flags => args[1], :mode => args[2]}.update opts
|
||||
@dbs, @env = WeakHash.new, Bdb::Env.new( 0)
|
||||
begin @env.open dir || '.', flags || INIT_TRANSACTION | CREATE, mode || 0
|
||||
@env.log_config = opts[:log_config] if opts[:log_config]
|
||||
begin @env.open opts[:dir]||'.', opts[:flags]|| INIT_TRANSACTION|CREATE, opts[:mode]||0
|
||||
rescue Object
|
||||
close
|
||||
raise
|
||||
|
|
|
@ -17,7 +17,7 @@ class WeakHash
|
|||
end
|
||||
@reclaim_key = lambda do |key_id|
|
||||
if @key_map.has_key? key_id
|
||||
@cache.delete @key_map[key_id]
|
||||
@cache.delete @key_map.delete(key_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue