Moved to rails cache.

This commit is contained in:
Martin Edenhofer 2012-04-16 11:45:02 +02:00
parent 1b3066a8b7
commit 5b988d073c
4 changed files with 26 additions and 14 deletions

View file

@ -148,21 +148,21 @@ class ApplicationController < ActionController::Base
user['links'] = [] user['links'] = []
# TEMP: compat. reasons # TEMP: compat. reasons
user[:preferences] = {} if !user[:preferences] user['preferences'] = {} if user['preferences'] == nil
topic = { topic = {
:title => 'Tickets', :title => 'Tickets',
:items => [ :items => [
{ {
:url => '', :url => '',
:name => 'open (' + user[:preferences][:tickets_open].to_s + ')', :name => 'open (' + user['preferences'][:tickets_open].to_s + ')',
:title => 'Open Tickets', :title => 'Open Tickets',
:class => 'user-tickets', :class => 'user-tickets',
:data => 'open' :data => 'open'
}, },
{ {
:url => '', :url => '',
:name => 'closed (' + user[:preferences][:tickets_closed].to_s + ')', :name => 'closed (' + user['preferences'][:tickets_closed].to_s + ')',
:title => 'Closed Tickets', :title => 'Closed Tickets',
:class => 'user-tickets', :class => 'user-tickets',
:data => 'closed' :data => 'closed'

View file

@ -1,8 +1,6 @@
class ApplicationModel < ActiveRecord::Base class ApplicationModel < ActiveRecord::Base
self.abstract_class = true self.abstract_class = true
@@cache = {}
def cache_update(o) def cache_update(o)
# puts 'u ' + self.class.to_s # puts 'u ' + self.class.to_s
if self.respond_to?('cache_delete') then self.cache_delete end if self.respond_to?('cache_delete') then self.cache_delete end
@ -11,21 +9,24 @@ class ApplicationModel < ActiveRecord::Base
end end
def cache_delete def cache_delete
# puts 'cache_delete', self.inspect # puts 'cache_delete', self.inspect
# puts 'cache_delete', self.id puts 'cache_delete', self.id
@@cache[self.to_s] = {} if !@@cache[self.to_s] key = self.class.to_s + '::' + self.id.to_s
@@cache[self.to_s][self.id] = nil puts key
Rails.cache.delete( key.to_s )
end end
def self.cache_set(data_id, data) def self.cache_set(data_id, data)
# puts 'cache_set', self.inspect # puts 'cache_set', self.inspect
# puts 'cache_set', self.to_s # puts 'cache_set', self.to_s
# puts 'cache_set', data_id puts 'cache_set', data_id
@@cache[self.to_s] = {} if !@@cache[self.to_s] key = self.to_s + '::' + data_id.to_s
@@cache[self.to_s][data_id] = data puts key
Rails.cache.write( key.to_s, data)
# @@cache[self.to_s][data_id] = data
end end
def self.cache_get(data_id) def self.cache_get(data_id)
# puts 'cache_get', data_id puts 'cache_get', data_id
# puts 'cache_get', self.inspect # puts 'cache_get', self.inspect
@@cache[self.to_s] = {} if !@@cache[self.to_s] key = self.to_s + '::' + data_id.to_s
return @@cache[self.to_s][data_id] if @@cache[self.to_s] Rails.cache.read( key.to_s )
end end
end end

View file

@ -61,5 +61,9 @@ module Zammad
# Version of your assets, change this if you want to expire all your assets # Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0' config.assets.version = '1.0'
# Use a different cache store in production
config.cache_store = :file_store, 'tmp/cache/file_store'
end end
end end

View file

@ -0,0 +1,7 @@
# clear cache
Rails.cache.clear
# to get rails caching working, load models
Dir.foreach("#{Rails.root}/app/models") do |model_name|
require_dependency model_name unless model_name == '.' || model_name == '..' || model_name == '.gitkeep'
end