Class: Inkit::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(secret) ⇒ Cache

Returns a new instance of Cache.



3
4
5
6
7
8
# File 'lib/cache.rb', line 3

def initialize(secret)
  @secret = secret
  @cache_dir = './.ink-cache'
  Dir.mkdir @cache_dir unless Dir.exists? @cache_dir
  @cached_at = {}
end

Instance Method Details

#[](name) ⇒ Object



14
15
16
# File 'lib/cache.rb', line 14

def [](name)
  File.read filename(name)
end

#[]=(name, data) ⇒ Object



9
10
11
12
13
# File 'lib/cache.rb', line 9

def []=(name,data)
  File.open( filename(name), "w+") do |io|
    io.write data
  end
end

#cached?(name) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/cache.rb', line 20

def cached?(name)
  File.exists? filename(name)
end

#cached_at(name) ⇒ Object



17
18
19
# File 'lib/cache.rb', line 17

def cached_at(name)
  File.stat(filename(name)).mtime.rfc2822
end