Module: Grass::Cache

Included in:
Source
Defined in:
lib/grass/cache.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clear_cacheObject



53
54
55
# File 'lib/grass/cache.rb', line 53

def clear_cache
  Grass.cache.delete self.class.generate_cachekey(self.key.fullpath,self.data) rescue nil
end

.included(base) ⇒ Object



24
25
26
27
# File 'lib/grass/cache.rb', line 24

def self.included(base)
  base.extend ClassMethods
  base.send :after_destroy, :clear_cache
end

.set_cacheObject



46
47
48
49
50
51
# File 'lib/grass/cache.rb', line 46

def set_cache
  Grass.cache.set(
  self.class.generate_cachekey(self.key.fullpath,self.data), 
  JSON.dump([self.mime_type, self.read].flatten)
  )
end

Instance Method Details

#cache!Object



36
37
38
# File 'lib/grass/cache.rb', line 36

def cache!
  set_cache
end

#commit!(result = nil) ⇒ Object



29
30
31
32
33
34
# File 'lib/grass/cache.rb', line 29

def commit! result = nil
  # clear_cache if precompile?
  super(result)
  set_cache if precompile?
  self
end

#precompile?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/grass/cache.rb', line 40

def precompile?
  self.binary.nil? && (self.type == "script" || self.type == "stylesheet")
end