https://github.com/leighmcculloch/filecache-ruby
A ruby gem that implements a file-based cache
https://github.com/leighmcculloch/filecache-ruby
Last synced: 28 days ago
JSON representation
A ruby gem that implements a file-based cache
- Host: GitHub
- URL: https://github.com/leighmcculloch/filecache-ruby
- Owner: leighmcculloch
- License: other
- Created: 2012-09-01T07:05:20.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2023-01-09T04:32:47.000Z (over 2 years ago)
- Last Synced: 2025-03-31T03:11:35.542Z (2 months ago)
- Language: Ruby
- Size: 15.6 KB
- Stars: 15
- Watchers: 3
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# filecache
[](http://badge.fury.io/rb/filecache)
FileCache is a file-based caching library for Ruby.
## Install
```
gem install filecache
```or
```ruby
gem 'filecache'
```## Usage
The following code will create a cache called `my-cache` rooted at `/tmp/caches` with an expiry time of `30` seconds, and a file hierarchy three directories deep.
```ruby
require 'filecache'cache = FileCache.new("my-cache", "/tmp/caches", 30, 3)
cache.set("key", "value")
puts(cache.get("key")) # "value"
sleep 30
puts(cache.get("key")) # nil
cache.get_or_set("key") { 1 } # 1
cache.get_or_set("key") { 2 } # 1 (cached value is returned, block is not executed)
```## Thanks
Thanks to [Simon Whitaker](http://github.com/simonwhitaker/filecache-ruby) who created this ruby gem.