jubishop / datacache

A wrapper for caching data until a timeout.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Datacache

RSpec Status Rubocop Status

A wrapper for caching data until a timeout.

Installation

Global installation

gem install datacache --source https://www.jubigems.org/

In a Gemfile

gem 'datacache', source: 'https://www.jubigems.org/'

Usage

cache = DataCache.new(10.seconds)
now = cache.fetch('time') { Time.now } # Future calls to cache.fetch('time') will return the same thing for 10 seconds

cache.fresh?('time') # true
sleep 10
cache.fresh?('time') # false

now = cache.set('time', 123) # Future calls to cache.fetch('time') will return 123 for 10 seconds.

cache.exists?('time') # true

cache.invalidate('time') # All references to 'time' are expunged.

cache.exists?('time') # false

License

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

About

A wrapper for caching data until a timeout.

License:MIT License


Languages

Language:Ruby 100.0%