Provide read and write buffers for Elixir. Use-case examples:
- Read buffer for a RDBMS.
- Write buffer for statsd counters.
- Write buffer to do batch API calls.
buffer is a library to create read or write buffer easily.
Update your applications list to include the buffer project:
defapplicationdo[applications: [:buffer]]endAdd the buffers to the supervisor when your application starts
defstart(_type,_args)doBuffer.Supervisor.start_child(BufferKeyListLimit)MyApplication.Supervisor.start_link()end## Declaration of the bufferdefmoduleBufferKeyListLimitdouseBuffer.Write.KeyList,interval: 1000,limit: 10defwrite(keylists)do## Write here your flushing functionendend## UsageBufferKeyListLimit.add(:key1,"value1")BufferKeyListLimit.add(:key1,"value2")BufferKeyListLimit.add(:key2,"value3")## The write function will receive this value[{:key1,["value1","value2"]},{:key2,["value3"]}]## APIBufferKeyListLimit.sync()BufferKeyListLimit.sync(:key1)## Declaration of the bufferdefmoduleBufferCountdouseBuffer.Write.Count,interval: 1000defwrite(counters)do## Write here your flushing functionendend## UsageBufferCount.incr(:key1)BufferCount.incr(:key1)BufferCount.incr(:key2,10)BufferCount.incr(:key2,15)## The write function will receive this value[{:key1,2},{:key2,25}]## APIBufferCount.sync()## Declaration of the bufferdefmoduleBufferReaddouseBuffer.Read,interval: 1000,timeout: 5_000,synchronize: truedefread()do## Write here your reading function[{:key1,"value1"},{:key2,"value2"}]enddefon_element_updated(keys)do#new key is added to the list, do something:spawn(fn()->IO.inspectkeysend)enddefupdated?(el1,el2)do#Customize function that determine if the object for one key has been# updatedel1!=el2endend## Options-synchronize: isusedtoforcesyncwhenthevalueisnil.-timeout: timeoutforthereadfunction-interval: autosyncinterval## Usage"value1"=BufferRead.read(:key1)## APIBufferRead.sync()