Class: Gub::Cache
- Inherits:
-
Object
- Object
- Gub::Cache
- Defined in:
- lib/gub/cache.rb
Instance Method Summary collapse
- #get(key) ⇒ Object
-
#initialize(base_dir) ⇒ Cache
constructor
A new instance of Cache.
- #set(key, value) ⇒ Object
Constructor Details
#initialize(base_dir) ⇒ Cache
Returns a new instance of Cache.
3 4 5 |
# File 'lib/gub/cache.rb', line 3 def initialize base_dir @base_dir = base_dir end |
Instance Method Details
#get(key) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/gub/cache.rb', line 14 def get key cached_path = @base_dir + '/' + key if File.exists? cached_path return IO.read cached_path end end |
#set(key, value) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/gub/cache.rb', line 7 def set key, value cached_path = @base_dir + '/' + key File.open(cached_path, 'w') do |f| f.puts value end end |