A cache store implementation which has two levels. In the first level it stores everything into memory in the same process and in the second level it stores everything on the filesystem.
The first level has a bounded size specified by the :size options to the initializer (default is 32Mb). When the first level exceeds the allotted size, a cleanup will occur which move to the second level store down to three quarters of the maximum size by moving the least recently used entries.
Add this line to your application's Gemfile:
gem "two_level_cache"And then execute:
$ bundle
Or install it yourself as:
$ gem install two_level_cache
Initialize Two Level Cache Store. You can pass all parameters available for MemoryStore and FileStore
store = TwoLevelCache::Store.new(cache_path: "tmp/cache")Writes item to the store
store.write("city", "Moscow") # => trueReads item from the store
store.write("city") # => "Moscow"Deletes item from the store
store.delete("city") # => trueDeletes all items from the cache.
store.clearPreemptively iterates through all stored keys and removes the ones which have expired.
store.cleanupBug reports and pull requests are welcome on GitHub at https://github.com/Ryazapov/two_level_cache.
The gem is available as open source under the terms of the MIT License.