Class: DataStorage
- Inherits:
-
Object
- Object
- DataStorage
- Defined in:
- lib/common/datastorage.rb
Instance Method Summary collapse
- #add(key, data) ⇒ Object
- #delete(key) ⇒ Object
- #delete_all ⇒ Object
- #get(key) ⇒ Object
-
#initialize(maxItemsInMemory, maxItemsOnDisk, persistentStorageHandler) ⇒ DataStorage
constructor
A new instance of DataStorage.
Constructor Details
#initialize(maxItemsInMemory, maxItemsOnDisk, persistentStorageHandler) ⇒ DataStorage
Returns a new instance of DataStorage.
26 27 28 29 30 31 32 33 |
# File 'lib/common/datastorage.rb', line 26 def initialize( maxItemsInMemory, maxItemsOnDisk, persistentStorageHandler ) @maxItemsInMemory = maxItemsInMemory # TODO: currently not used @maxItemsOnDisk = maxItemsOnDisk @persistentStorageHandler = persistentStorageHandler delete_all end |
Instance Method Details
#add(key, data) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/common/datastorage.rb', line 36 def add( key, data ) container = @items[key] if ( container == nil ) container = DataContainer.new( key, data, @persistentStorageHandler ) @items[key] = container @itemsInMemory.insert( 0, container ) elsif ( container.data_in_memory? ) @itemsInMemory.delete( container ) @itemsInMemory.insert( 0, container ) container.data = data else # on disk container.data = data @itemsInMemory.insert( 0, container ) end check_memory_items end |
#delete(key) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/common/datastorage.rb', line 59 def delete( key ) container = @items.delete( key ) if ( container != nil ) if ( container.data_in_memory? ) @itemsInMemory.delete( container ) end container.clear end end |
#delete_all ⇒ Object
88 89 90 91 92 93 |
# File 'lib/common/datastorage.rb', line 88 def delete_all @persistentStorageHandler.delete_all_files @itemsInMemory = [] @items = {} end |
#get(key) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/common/datastorage.rb', line 71 def get( key ) container = @items[key] if ( container == nil ) return nil end if ( container.data_in_memory? ) @itemsInMemory.delete( container ) end @itemsInMemory.insert( 0, container ) check_memory_items return container.data end |