Patch #1321 » 0002-remove-settings-cache-which-only-worked-per-request.patch
| app/controllers/application.rb | ||
|---|---|---|
|
end
|
||
|
|
||
|
def user_setup
|
||
|
# Check the settings cache for each request
|
||
|
Setting.check_cache
|
||
|
# Find the current user
|
||
|
User.current = find_current_user
|
||
|
end
|
||
| app/models/setting.rb | ||
|---|---|---|
|
validates_inclusion_of :name, :in => @@available_settings.keys
|
||
|
validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| @@available_settings[setting.name]['format'] == 'int' }
|
||
|
# Hash used to cache setting values
|
||
|
@cached_settings = {}
|
||
|
@cached_cleared_on = Time.now
|
||
|
|
||
|
def value
|
||
|
v = read_attribute(:value)
|
||
|
# Unserialize serialized settings
|
||
| ... | ... | |
|
|
||
|
# Returns the value of the setting named name
|
||
|
def self.[](name)
|
||
|
v = @cached_settings[name]
|
||
|
v ? v : (@cached_settings[name] = find_or_default(name).value)
|
||
|
find_or_default(name).value
|
||
|
end
|
||
|
|
||
|
def self.[]=(name, v)
|
||
|
setting = find_or_default(name)
|
||
|
setting.value = (v ? v : "")
|
||
|
@cached_settings[name] = nil
|
||
|
setting.save
|
||
|
setting.value
|
||
|
end
|
||
| ... | ... | |
|
per_page_options.split(%r{[\s,]}).collect(&:to_i).select {|n| n > 0}.sort
|
||
|
end
|
||
|
|
||
|
# Checks if settings have changed since the values were read
|
||
|
# and clears the cache hash if it's the case
|
||
|
# Called once per request
|
||
|
def self.check_cache
|
||
|
settings_updated_on = Setting.maximum(:updated_on)
|
||
|
if settings_updated_on && @cached_cleared_on <= settings_updated_on
|
||
|
@cached_settings.clear
|
||
|
@cached_cleared_on = Time.now
|
||
|
logger.info "Settings cache cleared." if logger
|
||
|
end
|
||
|
end
|
||
|
|
||
|
private
|
||
|
# Returns the Setting instance for the setting named name
|
||
- « Previous
- 1
- 2
- Next »