Skip to content

Ryazapov/two_level_cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TwoLevelCache

Build Status

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.

Installation

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

Usage

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") # => true

Reads item from the store

store.write("city") # => "Moscow"

Deletes item from the store

store.delete("city") # => true

Deletes all items from the cache.

store.clear

Preemptively iterates through all stored keys and removes the ones which have expired.

store.cleanup

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Ryazapov/two_level_cache.

License

The gem is available as open source under the terms of the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published