forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
speed up startup (avoid loading some gems on startup)
correct group permission leaks add Discourse.cache for richer caching support
- Loading branch information
1 parent
9b33e82
commit b6bf95e
Showing
21 changed files
with
250 additions
and
66 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
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
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Standard Rails.cache is lacking support for this interface, possibly yank all in from redis:cache and start using this instead | ||
# | ||
|
||
class Cache | ||
def initialize(redis=nil) | ||
@redis = redis | ||
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 | ||
end | ||
|
||
if family = family_key(options[:family]) | ||
redis.sadd(family, key) | ||
end | ||
|
||
result | ||
end | ||
|
||
def delete(key) | ||
redis.del(key) | ||
end | ||
|
||
def delete_by_family(key) | ||
k = family_key(key) | ||
redis.smembers(k).each do |member| | ||
delete(member) | ||
end | ||
redis.del(k) | ||
end | ||
|
||
private | ||
|
||
def family_key(name) | ||
if name | ||
"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
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
Oops, something went wrong.