Class: Ruty::Loaders::MemcachingFilesystem

Inherits:
Filesystem show all
Defined in:
lib/ruty/loaders/filesystem.rb

Overview

like the normal filesystem loader but uses memcaching

Instance Attribute Summary

Attributes inherited from Ruty::Loader

#options

Instance Method Summary collapse

Methods inherited from Filesystem

#initialize, #load_local, #path_for?

Methods inherited from Ruty::Loader

#get_template, #initialize, #load_local

Constructor Details

This class inherits a constructor from Ruty::Loaders::Filesystem

Instance Method Details

#initialze(options = nil) ⇒ Object

the memcaching filesystem loader takes the same arguments as the normal filesystem loader and additionally a key called :amount that indicates the maximum amount of cached templates. The amount defaults to 20.


61
62
63
64
65
# File 'lib/ruty/loaders/filesystem.rb', line 61

def initialze options=nil
  super(options)
  @amount = @options[:amount] || 20
  @cache = {}
end

#load_cached(name, parent = nil) ⇒ Object


67
68
69
70
71
72
73
# File 'lib/ruty/loaders/filesystem.rb', line 67

def load_cached name, parent=nil
  path = path_for?(name, parent)
  return @cache[path] if @cache.include?(path)
  nodelist = super(name, parent, path)
  @cache.clear if @cache.size >= @amount
  @cache[path] = nodelist
end