Skip to content

Commit

Permalink
[api] reset cache of project/package meta xml also in failure case wh…
Browse files Browse the repository at this point in the history
…en write to backend failed
  • Loading branch information
adrianschroeter committed Dec 3, 2012
1 parent 2f72a5e commit 46b1631
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/api/app/models/package.rb
Expand Up @@ -33,6 +33,7 @@ class ReadSourceAccessError < Exception; end
attr_accessible :name, :title, :description
after_save :write_to_backend
after_save :update_activity
after_rollback :reset_cache

default_scope { where("packages.db_project_id not in (?)", ProjectUserRoleRelationship.forbidden_project_ids ) }

Expand Down Expand Up @@ -612,9 +613,12 @@ def store(opts = {})
save!
end

def write_to_backend
# expire cache
def reset_cache
Rails.cache.delete('meta_package_%d' % id)
end

def write_to_backend
reset_cache
@commit_opts ||= {}
#--- write through to backend ---#
if CONFIG['global_write_through']
Expand Down
8 changes: 7 additions & 1 deletion src/api/app/models/project.rb
Expand Up @@ -19,6 +19,8 @@ def errorcode

before_destroy :cleanup_before_destroy
after_save 'ProjectUserRoleRelationship.discard_cache'
after_rollback :reset_cache
after_rollback 'ProjectUserRoleRelationship.discard_cache'

has_many :project_user_role_relationships, :dependent => :delete_all, foreign_key: :db_project_id
has_many :project_group_role_relationships, :dependent => :delete_all, foreign_key: :db_project_id
Expand Down Expand Up @@ -667,7 +669,7 @@ def update_from_xml(xmlhash, force=nil)
def write_to_backend
logger.debug "write_to_backend"
# expire cache
Rails.cache.delete('meta_project_%d' % id)
reset_cache
@commit_opts ||= {}

if CONFIG['global_write_through']
Expand All @@ -688,6 +690,10 @@ def store(opts = {})
end
end

def reset_cache
Rails.cache.delete('meta_project_%d' % id)
end

def store_attribute_axml( attrib, binary=nil )

raise SaveError, "attribute type without a namespace " if not attrib.namespace
Expand Down

0 comments on commit 46b1631

Please sign in to comment.