Class: Githu3::Cache::Disk
- Inherits:
-
Object
- Object
- Githu3::Cache::Disk
- Defined in:
- lib/githu3/cache/disk.rb
Constant Summary collapse
- DEFAULTS =
{ :path => '/tmp/githu3', :namespace => 'cache', :expire => 120 }
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #get(k) ⇒ Object
-
#initialize(opts = {}) ⇒ Disk
constructor
A new instance of Disk.
- #set(k, val, opts = {}) ⇒ Object
Constructor Details
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/githu3/cache/disk.rb', line 6 def config @config end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
6 7 8 |
# File 'lib/githu3/cache/disk.rb', line 6 def store @store end |
Instance Method Details
#get(k) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/githu3/cache/disk.rb', line 20 def get k val = nil file_path = ::File.join(@path, k) if ::File.exists?(file_path) if (Time.now - ::File.atime(file_path)) < @config[:expire] val = Marshal.load(::File.read(file_path)) else FileUtils.rm(file_path) end else end val end |
#set(k, val, opts = {}) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/githu3/cache/disk.rb', line 34 def set k, val, opts={} file_path = ::File.join(@path, k) f = open(file_path, 'wb') f.write(Marshal.dump(val)) f.close end |