Module: Innate::Cache::FileBased

Included in:
Marshal, YAML
Defined in:
/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/cache/file_based.rb

Overview

Used by caches that serialize their contents to the filesystem. Right now we do not lock around write access to the file outside of the process, that means that all FileBased caches are not safe for use if you need more than one instance of your application.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) filename (readonly)

Returns the value of attribute filename



9
10
11
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/cache/file_based.rb', line 9

def filename
  @filename
end

Instance Method Details

- (Object) cache_clear



21
22
23
24
25
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/cache/file_based.rb', line 21

def cache_clear
  FileUtils.mkdir_p(@dir)
  FileUtils.rm_f(@filename)
  @store = self.class::STORE.new(@filename)
end

- (Object) cache_delete(*args)



35
36
37
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/cache/file_based.rb', line 35

def cache_delete(*args)
  super{|key| transaction{|store| store.delete(key) } }
end

- (Object) cache_fetch(*args)



31
32
33
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/cache/file_based.rb', line 31

def cache_fetch(*args)
  super{|key| transaction{|store| store[key] } }
end

- (Object) cache_setup(*args)



11
12
13
14
15
16
17
18
19
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/cache/file_based.rb', line 11

def cache_setup(*args)
  @prefix = args.compact.join('-')

  @dir = File.join(Dir.tmpdir, self.class::DIR)
  FileUtils.mkdir_p(@dir)

  @filename = File.join(@dir, @prefix + self.class::EXT)
  @store = self.class::STORE.new(@filename)
end

- (Object) cache_store(*args)



27
28
29
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/cache/file_based.rb', line 27

def cache_store(*args)
  super{|key, value| transaction{|store| store[key] = value } }
end

- (Object) transaction(&block)



39
40
41
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/cache/file_based.rb', line 39

def transaction(&block)
  Innate.sync{ @store.transaction(&block) }
end