Module: Slugged::Caching
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/slugged/caching.rb
Overview
Mixin for adding simple caching support to models using slugged. Usually included by passing the :cache option as true (by default it is true, you can disable by passing :cache as false or nil).
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#globally_cache_slug ⇒ Object
Automatically called in after_save, will cache this records id with to match the current records slug / scope.
-
#remove_slug_history! ⇒ Object
Wraps remove_slug_history! to remove each of the slugs recording in this models slug history.
Instance Method Details
#globally_cache_slug ⇒ Object
Automatically called in after_save, will cache this records id with to match the current records slug / scope
20 21 22 23 24 25 26 27 28 |
# File 'lib/slugged/caching.rb', line 20 def globally_cache_slug return unless send(:"#{self.cached_slug_column}_changed?") value = self.to_slug self.class.cache_slug_lookup!(value, self) if value.present? unless use_slug_history value = send(:"#{self.cached_slug_column}_was") self.class.cache_slug_lookup!(value, nil) end end |
#remove_slug_history! ⇒ Object
Wraps remove_slug_history! to remove each of the slugs recording in this models slug history.
32 33 34 35 |
# File 'lib/slugged/caching.rb', line 32 def remove_slug_history! previous_slugs.each { |s| self.class.cache_slug_lookup!(s, nil) } super end |