Skip to content

Commit

Permalink
[api][webui] Cleanup architecture caching
Browse files Browse the repository at this point in the history
* Refactor archcache method
* Update callbacks
  • Loading branch information
bgeuken committed Apr 12, 2016
1 parent fef4eed commit c58df9b
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/api/app/models/architecture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class Architecture < ActiveRecord::Base
has_many :flags

#### Callbacks macros: before_save, after_save, etc.
after_save 'Architecture.discard_cache'
after_destroy 'Architecture.discard_cache'
after_save :discard_cache
after_destroy :discard_cache

#### Scopes (first the default_scope macro if is used)
scope :available, -> { where(available: 1) }
Expand All @@ -23,17 +23,13 @@ class Architecture < ActiveRecord::Base

#### Class methods using self. (public and then private)

def self.discard_cache
def discard_cache
Rails.cache.delete("archcache")
end

def self.archcache
return Rails.cache.fetch("archcache") do
ret = Hash.new
Architecture.all.each do |arch|
ret[arch.name] = arch
end
ret
Rails.cache.fetch("archcache") do
Architecture.all.map { |arch| [arch.name, arch] }.to_h
end
end

Expand Down

0 comments on commit c58df9b

Please sign in to comment.