Module: ApiResource
- Defined in:
- lib/ocean/api_resource.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#invalidate(avoid_self = false) ⇒ Object
Invalidate the member and all its collections in Varnish using a
BAN
requests to all caches in the Ocean environment. -
#touch_both(other) ⇒ Object
Convenience function used to touch two resources in one call, e.g:.
Class Method Details
.included(base) ⇒ Object
3 4 5 |
# File 'lib/ocean/api_resource.rb', line 3 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#invalidate(avoid_self = false) ⇒ Object
Invalidate the member and all its collections in Varnish using a BAN
requests to all caches in the Ocean environment. The BAN
request are done in parallel. The number of BAN
requests, and the exact URI
composition in each request, is determined by the invalidate_member:
arg to the ocean_resource_model
declaration in the model.
The optional arg avoid_self
, if true (the default is false), avoids invalidating the basic resource itself: only its derived collections are invalidated. This is useful when instantiating a new resource.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/ocean/api_resource.rb', line 163 def invalidate(avoid_self=false) self.class.invalidate #resource_name = self.class.name.pluralize.underscore varnish_invalidate_member.each do |thing| if thing.is_a?(String) #Api.ban "/v[0-9]+/#{resource_name}/#{self.id}#{thing}" if !avoid_self # Invalidate every GET request where the URI mentions this UUID Api.ban "#{self.id}" if !avoid_self else # Call the thing and let the resulting string be banned Api.ban "#{thing.call(self)}" end end end |
#touch_both(other) ⇒ Object
Convenience function used to touch two resources in one call, e.g:
@api_user.touch_both(@connectee)
146 147 148 149 |
# File 'lib/ocean/api_resource.rb', line 146 def touch_both(other) touch other.touch end |