-
Notifications
You must be signed in to change notification settings - Fork 2
Superstores
Archivist stores all of the data it receives in a compressed format. This is done to minimize load times, but can in some cases present a problem. If your use case is such that you almost never need to access your entire data set all at once, then having to decompress the entire store every time is quite wasteful. This is where superstores come in.
A superstore is any store which in its implementation, creates and/or manages other stores. Here is a relatively simple superstore which implements a time machine:
-- data time machine
local storeMethods = {
Commit = function(self, data)
-- typically you will let Archivist generate a storeID for your stubstores
local _, storeID = Archivist:Create("RawData", nil, data)
self.history[#self.history + 1] = storeID
end,
Retrieve = function(self, index)
if index <= 0 then
index = #self.history + index
end
if self.history[index] then
return Archivist:Open("RawData", self.history[index])
end
end
}
Archivist:RegisterStoreType{
id = "TimeMachine",
version = 1,
Create = function(self)
local store = {
history = {}
}
Mixin(store, storeMethods)
return store, store
end,
Open = function(self, store)
Mixin(store, storeMethods)
return store
end,
Commit = function(self, store) return store end,
Close = function(self, store) return store end
}
With this superstore, you can create a permanent record of changes to your active data set. If you ever need to rewind those changes (go "back in time"), then you can easily retrieve previous iteration to replace your active data with, without having to unpack every single iteration, which would quickly become unpleasantly slow if that data is modified frequently.