Class: DocumentSweeper
- Inherits:
-
ActionController::Caching::Sweeper
- Object
- ActionController::Caching::Sweeper
- DocumentSweeper
- Defined in:
- app/models/document_sweeper.rb
Instance Method Summary collapse
- #after_destroy(document) ⇒ Object
- #after_save(document) ⇒ Object
-
#clear_document_cache(document) ⇒ Object
We dont need to expire the cache for the parent as a document always touches its parent after_save, which will cause this method to be run for the parent as well.
Instance Method Details
#after_destroy(document) ⇒ Object
8 9 10 |
# File 'app/models/document_sweeper.rb', line 8 def after_destroy(document) clear_document_cache(document) end |
#after_save(document) ⇒ Object
4 5 6 |
# File 'app/models/document_sweeper.rb', line 4 def after_save(document) clear_document_cache(document) end |
#clear_document_cache(document) ⇒ Object
We dont need to expire the cache for the parent as a document always touches its parent after_save, which will cause this method to be run for the parent as well.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/document_sweeper.rb', line 16 def clear_document_cache(document) expire_fragment :recent_posts expire_fragment :menu cache_paths = [] cache_paths << File.join(RAILS_ROOT, 'public', 'cache', document.path) cache_paths.each do | cache_path | Rails.logger.debug 'Deleting CACHE: ' + cache_path FileUtils.rm_rf cache_path if File.exists? cache_path end end |