Skip to content

Commit 7a301e5

Browse files
committed
Remove clear_all method and add comments to clear_all rake task
1 parent 136ba14 commit 7a301e5

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,16 @@ CriticalPathCss.generate_all # Generates critical CSS for all routes i
9595
CriticalPathCss.clear route # Removes the CSS for the given route from the cache
9696

9797
CriticalPathCss.clear_matched routes # Removes the CSS for the matched routes from the cache
98-
99-
CriticalPathCss.clear_all # Clears all CSS from the cache
10098
```
10199

100+
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).
101+
102102
In addition to the `critical_path_css:generate` rake task described above, you also have access to task which clears the CSS cache:
103103

104104
```
105105
rake critical_path_css:clear_all
106106
```
107-
108-
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).
107+
NOTE: The `critical_path_css:clear_all` rake task may need to be customized to suit your particular cache implementation.
109108

110109
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.
111110

lib/critical-path-css-rails.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ def self.clear_matched(routes)
2222
Rails.cache.delete_matched(routes,namespace: CACHE_NAMESPACE)
2323
end
2424

25-
def self.clear_all
26-
self.clear_matched('*')
27-
end
28-
2925
def self.fetch(route)
3026
Rails.cache.read(route, namespace: CACHE_NAMESPACE) || ''
3127
end

lib/tasks/critical_path_css.rake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ namespace :critical_path_css do
77
end
88
desc 'Clear all critical CSS from the cache'
99
task clear_all: :environment do
10-
CriticalPathCss.clear_all
10+
# Use the following for Redis cache implmentations
11+
CriticalPathCss.clear_matched('*')
12+
# Some other cache implementations may require the following syntax instead
13+
# CriticalPathCss.clear_matched(/.*/)
1114
end
1215
end
1316

0 commit comments

Comments
 (0)