Weakhash: self cleaning cache. SBDB::Env#new: Hash-options added

This commit is contained in:
Denis Knauf 2010-03-07 22:01:05 +01:00
parent bddc461ca4
commit a4d1031d93
3 changed files with 14 additions and 4 deletions

View file

@ -54,7 +54,8 @@ module SBDB
@home, @db = opts[:env], opts[:env] ? opts[:env].bdb_object.db : Bdb::Db.new @home, @db = opts[:env], opts[:env] ? opts[:env].bdb_object.db : Bdb::Db.new
opts[:type] = TYPES.index(self.class) || UNKNOWN opts[:type] = TYPES.index(self.class) || UNKNOWN
@db.re_len = opts[:re_len] if opts[:re_len] @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 rescue Object
close close
raise $! raise $!

View file

@ -41,9 +41,18 @@ module SBDB
open Unknown, file, *p, &e open Unknown, file, *p, &e
end 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) @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 rescue Object
close close
raise raise

View file

@ -17,7 +17,7 @@ class WeakHash
end end
@reclaim_key = lambda do |key_id| @reclaim_key = lambda do |key_id|
if @key_map.has_key? 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 end
end end