-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUGFIX: redis-rails has always been a problem child
implemented an ActiveSupport::Cache::Store for our internal use. * allows for expire by family * works correctly in multisite * namespaced correctly Removed redis-rails from the project, no longer needed
- Loading branch information
1 parent
5f6836b
commit b703d8c
Showing
8 changed files
with
102 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,72 @@ | ||
# Standard Rails.cache is lacking support for this interface, possibly yank all in from redis:cache and start using this instead | ||
# | ||
# Discourse specific cache supports expire by family missing from standard cache | ||
|
||
class Cache | ||
def initialize(redis=nil) | ||
@redis = redis | ||
class Cache < ActiveSupport::Cache::Store | ||
|
||
def initialize(opts = {}) | ||
opts[:namespace] ||= "_CACHE_" | ||
super(opts) | ||
end | ||
|
||
def redis | ||
@redis || $redis | ||
end | ||
|
||
def fetch(key, options={}) | ||
result = redis.get key | ||
if result.nil? | ||
if expiry = options[:expires_in] | ||
if block_given? | ||
result = yield | ||
redis.setex(key, expiry, result) | ||
end | ||
else | ||
if block_given? | ||
result = yield | ||
redis.set(key, result) | ||
end | ||
end | ||
$redis | ||
end | ||
|
||
def delete_by_family(key) | ||
k = family_key(key, options) | ||
redis.smembers(k).each do |member| | ||
redis.del(member) | ||
end | ||
redis.del(k) | ||
end | ||
|
||
if family = family_key(options[:family]) | ||
redis.sadd(family, key) | ||
def reconnect | ||
redis.reconnect | ||
end | ||
|
||
def clear | ||
redis.keys.each do |k| | ||
redis.del(k) if k =~ /^_CACHE_:/ | ||
end | ||
end | ||
|
||
result | ||
def namespaced_key(key, opts=nil) | ||
opts ||= options | ||
super(key,opts) | ||
end | ||
|
||
def delete(key) | ||
redis.del(key) | ||
protected | ||
|
||
def read_entry(key, options) | ||
if data = redis.get(key) | ||
ActiveSupport::Cache::Entry.new data | ||
end | ||
end | ||
|
||
def delete_by_family(key) | ||
k = family_key(key) | ||
redis.smembers(k).each do |member| | ||
delete(member) | ||
def write_entry(key, entry, options) | ||
if expiry = options[:expires_in] | ||
redis.setex(key, expiry, entry.value) | ||
else | ||
redis.set(key, entry.value) | ||
end | ||
redis.del(k) | ||
|
||
if family = family_key(options[:family], options) | ||
redis.sadd(family, key) | ||
end | ||
|
||
true | ||
end | ||
|
||
def delete_entry(key, options) | ||
redis.del key | ||
end | ||
|
||
private | ||
|
||
def family_key(name) | ||
def family_key(name, options) | ||
if name | ||
"FAMILY_#{name}" | ||
key = namespaced_key(name, options) | ||
key << "FAMILY:#{name}" | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ def self.create_new_context | |
"vendor/assets/javascripts/rsvp.js", | ||
Rails.configuration.ember.handlebars_location) | ||
|
||
ctx.eval("var Discourse = {}; Discourse.SiteSettings = #{SiteSetting.client_settings_json};") | ||
ctx.eval("var Discourse = {}; Discourse.SiteSettings = {};") | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
SamSaffron
Author
Member
|
||
ctx.eval("var window = {}; window.devicePixelRatio = 2;") # hack to make code think stuff is retina | ||
ctx.eval("var I18n = {}; I18n.t = function(a,b){ return helpers.t(a,b); }"); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Was this meant to be in this commit?