Class: Archipelago::Hashish::BerkeleyHashish
- Inherits:
-
Object
- Object
- Archipelago::Hashish::BerkeleyHashish
show all
- Includes:
- CachedHashish
- Defined in:
- lib/archipelago/hashish.rb
Overview
A CachedHashish backed by a few BDB::Hashes.
Instance Method Summary
collapse
#[], #[]=, #delete, #first, #forget, #get_deep_clone, #get_from_db, #include?, #initialize_cached_hashish, #last, #store_if_changed, #timestamp, #without_lock, #write_to_db
#lock_on, #mon_check_owner, #synchronize_on, #unlock_on
Constructor Details
Initialize an instance with the name
and BDB::Env env
.
348
349
350
351
352
353
|
# File 'lib/archipelago/hashish.rb', line 348
def initialize(name, env)
super()
initialize_cached_hashish
@content_db = env.open_db(BDB::HASH, name, "content", BDB::CREATE)
@timestamps_db = env.open_db(BDB::HASH, name, "timestamps", BDB::CREATE | BDB::NOMMAP)
end
|
Instance Method Details
#changed?(serialized_key, serialized_value) ⇒ Boolean
371
372
373
374
|
# File 'lib/archipelago/hashish.rb', line 371
def changed?(serialized_key, serialized_value)
old_serialized_value = @content_db[serialized_key]
return old_serialized_value && old_serialized_value != serialized_value
end
|
#close! ⇒ Object
354
355
356
357
|
# File 'lib/archipelago/hashish.rb', line 354
def close!
@content_db.close
@timestamps_db.close
end
|
#db_include?(key) ⇒ Boolean
379
380
381
|
# File 'lib/archipelago/hashish.rb', line 379
def db_include?(key)
return !@content_db[Marshal.dump(key)].nil?
end
|
#do_delete_from_persistence(serialized_key) ⇒ Object
367
368
369
370
|
# File 'lib/archipelago/hashish.rb', line 367
def do_delete_from_persistence(serialized_key)
@timestamps_db[serialized_key] = nil
@content_db[serialized_key] = nil
end
|
#do_get_from_db(serialized_key) ⇒ Object
382
383
384
|
# File 'lib/archipelago/hashish.rb', line 382
def do_get_from_db(serialized_key)
return @content_db[serialized_key]
end
|
#do_get_timestamp_from_db(serialized_key) ⇒ Object
364
365
366
|
# File 'lib/archipelago/hashish.rb', line 364
def do_get_timestamp_from_db(serialized_key)
return @timestamps_db[serialized_key]
end
|
#do_write_to_db(key, serialized_key, serialized_value, now) ⇒ Object
375
376
377
378
|
# File 'lib/archipelago/hashish.rb', line 375
def do_write_to_db(key, serialized_key, serialized_value, now)
@content_db[serialized_key] = serialized_value
@timestamps_db[serialized_key] = Marshal.dump(now)
end
|
#each(callable) ⇒ Object
358
359
360
361
362
363
|
# File 'lib/archipelago/hashish.rb', line 358
def each(callable)
@content_db.each do |serialized_key, serialized_value|
key = Marshal.load(serialized_key)
callable.call(key, self.[](key))
end
end
|