mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: allow a central redis cache for assets
This commit is contained in:
@@ -21,14 +21,31 @@ task 'assets:precompile:before' do
|
||||
|
||||
module ::Sprockets
|
||||
|
||||
def self.redis
|
||||
@redis ||=
|
||||
(
|
||||
redis_url = GlobalSetting.asset_redis_url
|
||||
if redis_url.present?
|
||||
uri = URI.parse(redis_url)
|
||||
options = {}
|
||||
options[:password] = uri.password if uri.password.present?
|
||||
options[:host] = uri.host
|
||||
options[:port] = uri.port || 6379
|
||||
Redis.new(options)
|
||||
else
|
||||
DiscourseRedis.raw_connection
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
def self.cache_compiled(type, data)
|
||||
digest = Digest::SHA1.hexdigest(data)
|
||||
key = "SPROCKETS_#{type}_#{digest}"
|
||||
if compiled = $redis.get(key)
|
||||
$redis.expire(key, 1.week)
|
||||
if compiled = redis.get(key)
|
||||
redis.expire(key, 1.week)
|
||||
else
|
||||
compiled = yield
|
||||
$redis.setex(key, 1.week, compiled)
|
||||
redis.setex(key, 1.week, compiled)
|
||||
end
|
||||
compiled
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user