Skip to content

Commit

Permalink
Remove clear_all method and add comments to clear_all rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
taranda committed Nov 4, 2016
1 parent 136ba14 commit 7a301e5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,16 @@ CriticalPathCss.generate_all # Generates critical CSS for all routes i
CriticalPathCss.clear route # Removes the CSS for the given route from the cache

CriticalPathCss.clear_matched routes # Removes the CSS for the matched routes from the cache

CriticalPathCss.clear_all # Clears all CSS from the cache
```

NOTE: The `clear_matched` method will not work with Memcached due to the latter's incompatibility with Rails' `delete_matched` method. We recommend using an alternative cache such as [Redis](https://github.com/redis-store/redis-rails).

In addition to the `critical_path_css:generate` rake task described above, you also have access to task which clears the CSS cache:

```
rake critical_path_css:clear_all
```

NOTE: The `clear_all` and `clear_matched` methods will not work with Memcached due to the latter's incompatibility with Rails' `delete_matched` method. We recommend using an alternative cache such as [Redis](https://github.com/redis-store/redis-rails).
NOTE: The `critical_path_css:clear_all` rake task may need to be customized to suit your particular cache implementation.

Careful use of these methods allows the developer to generate critical path CSS dynamically within the app. The user should strongly consider using a [background job](http://edgeguides.rubyonrails.org/active_job_basics.html) when generating CSS in order to avoid tying up a rails thread. The `generate` method will send a GET request to your server which could cause infinite recursion if the developer is not careful.

Expand Down
4 changes: 0 additions & 4 deletions lib/critical-path-css-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ def self.clear_matched(routes)
Rails.cache.delete_matched(routes,namespace: CACHE_NAMESPACE)
end

def self.clear_all
self.clear_matched('*')
end

def self.fetch(route)
Rails.cache.read(route, namespace: CACHE_NAMESPACE) || ''
end
Expand Down
5 changes: 4 additions & 1 deletion lib/tasks/critical_path_css.rake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ namespace :critical_path_css do
end
desc 'Clear all critical CSS from the cache'
task clear_all: :environment do
CriticalPathCss.clear_all
# Use the following for Redis cache implmentations
CriticalPathCss.clear_matched('*')
# Some other cache implementations may require the following syntax instead
# CriticalPathCss.clear_matched(/.*/)
end
end

Expand Down

0 comments on commit 7a301e5

Please sign in to comment.