Multi process and thread safe cache
# Process1
import lilcache
lilcache.set('a', 'b')
# Process2
import lilcache
lilcache.get('a')
# Process3
import lilcache
lilcache.pop('a')
Named cache
import lilcache
lilcache.init('foo_cache')
lilcache.set('a', 'b')
Snapshot at regular intervals
import lilcache
lilcache.init('foo_cache', snapshot='120s')
lilcache.set('a', 'b')
Delete cache
import lilcache
lilcache.set('a', 'b')
lilcache.purge()
Expire cache
import lilcache
lilcache.init('foo_cache', expires='1d')
lilcache.set('a', 'b')
RESTful
import lilcache
lilcache.init('foo_cache')
lilcache.start(host='0.0.0.0', port=5001) # Blocking call
$ curl localhost:5001/get?key=a
'b'
$ curl localhost:5001/set?key=a&value=b
OK
Cache path
import lilcache
lilcache.init('foo_cache', root='/home/user/secured-directory')
lilcache.set('password', 'hello123')
Logging
import lilcache
lilcache.init(loglevel='DEBUG') # log file will be stored under root
lilcache.set('a', 'b')
Inter process communication approaches
P1 creates FIFO (named pipe)
Other processes communicate to P1 about operations (get/set/delete)
P1 acts as master process and manages the state in memory (but what if it exits, electing new master?)
P1 will be responsible for creating cache snapshots
What if P1 (manager process) exists
Need election algorithm (think more!)
To retain the state of cache in newly elected manager (P2), we need to maintain list of set/delete operations
This list of operations will be optimized (sort of tree shaking) time to time
P1 creates local socket
Other processes communicate to P1 about operations (get/set/delete)
P1 acts as master process and manages the state in memory (but what if it exits, electing new master?)
P1 will be responsible for creating snapshots
What if P1 (manager process) exists
Need election algorithm (think more!)
To retain the state of cache in newly elected manager (P2), we need to maintain list of set/delete operations
This list of operations will be optimized (sort of tree shaking) time to time
"Incoordinated" cache | No IPC
No concept of master process
Each process will read from disk (get/set/delete)
Each process can have a local in-memory cache (but problem of synchronization)