Class: Friendly::Cache

Inherits:
Storage show all
Defined in:
lib/friendly/cache.rb,
lib/friendly/cache/by_id.rb

Direct Known Subclasses

ByID

Defined Under Namespace

Classes: ByID

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Storage

#all, #count, #create, #destroy, #first, #satisfies?, #update

Constructor Details

#initialize(klass, fields, options = {}, cache = Friendly.cache) ⇒ Cache

Returns a new instance of Cache.



17
18
19
20
21
22
# File 'lib/friendly/cache.rb', line 17

def initialize(klass, fields, options = {}, cache = Friendly.cache)
  @klass   = klass
  @fields  = fields
  @cache   = cache
  @version = options[:version] || 0
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



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

def cache
  @cache
end

#fieldsObject (readonly)

Returns the value of attribute fields.



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

def fields
  @fields
end

#klassObject (readonly)

Returns the value of attribute klass.



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

def klass
  @klass
end

#versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

Class Method Details

.cache_for(klass, fields, options) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/friendly/cache.rb', line 6

def cache_for(klass, fields, options)
  unless fields == [:id]
    raise NotSupported, "Caching is only possible by id at the moment."
  end

  ByID.new(klass, fields, options)
end