Skip to content

Commit 136ba14

Browse files
committed
Set critical CSS cache entries to never expire.
1 parent 6400619 commit 136ba14

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ In addition to the `critical_path_css:generate` rake task described above, you a
105105
rake critical_path_css:clear_all
106106
```
107107

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).
109+
108110
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.
109111

110112
A user can use these methods to [dynamically generate critical path CSS](https://gist.github.com/taranda/1597e97ccf24c978b59aef9249666c77) without using the `rake critical_path_css:generate` rake task and without hardcoding the application's routes into `config/critical_path_css.yml`. See [this Gist](https://gist.github.com/taranda/1597e97ccf24c978b59aef9249666c77) for an example of such an implementation.

lib/critical-path-css-rails.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module CriticalPathCss
44
CACHE_NAMESPACE = 'critical-path-css'
55

66
def self.generate(route)
7-
Rails.cache.write(route, CssFetcher.new.fetch_route(route), namespace: CACHE_NAMESPACE)
7+
Rails.cache.write(route, CssFetcher.new.fetch_route(route),
8+
namespace: CACHE_NAMESPACE, expires_in: nil)
89
end
910

1011
def self.generate_all

0 commit comments

Comments
 (0)