Class: Friendly::Cache

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

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

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

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

- (Object) cache (readonly)

Returns the value of attribute cache



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

def cache
  @cache
end

- (Object) fields (readonly)

Returns the value of attribute fields



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

def fields
  @fields
end

- (Object) klass (readonly)

Returns the value of attribute klass



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

def klass
  @klass
end

- (Object) version (readonly)

Returns the value of attribute version



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

def version
  @version
end

Class Method Details

+ (Object) cache_for(klass, fields, options)



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