Skip to content

Commit

Permalink
make cache preloading settable as environmental variable
Browse files Browse the repository at this point in the history
  • Loading branch information
ethn committed Nov 4, 2010
1 parent 8387250 commit e6fb47c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/wagn/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def initialize_on_startup
@@preload = false
if RAILS_ENV =~ /cucumber|test/
Card.cache = Wagn::Cache.new nil, system_prefix
preload_cache_for_tests if RAILS_ENV=='cucumber'
preload_cache_for_tests if preload_cache?
else
Card.cache = Wagn::Cache.new Rails.cache, system_prefix
end
Expand All @@ -20,6 +20,10 @@ def preload_cache_for_tests
Role[:auth]; Role[:anon]
@@frozen = Marshal.dump([Card.cache, Role.cache])
end

def preload_cache?
@@preload = (RAILS_ENV=='cucumber' || ENV['PRELOAD_CACHE'])
end

def system_prefix
cache_env = (RAILS_ENV == 'cucumber') ? 'test' : RAILS_ENV
Expand All @@ -28,12 +32,12 @@ def system_prefix

def re_initialize_for_new_request
Card.cache.system_prefix = system_prefix
reset_local unless @@preload
reset_local unless preload_cache?
end

def reset_for_tests
reset_global
Card.cache, Role.cache = Marshal.load(@@frozen) if @@preload
Card.cache, Role.cache = Marshal.load(@@frozen) if preload_cache?
end


Expand Down

0 comments on commit e6fb47c

Please sign in to comment.