module RPM::Repository::Caching

RPM Repository Caching module Mix for RPM::Repository to realize MD in-memory caching

Private Instance Methods

get_packages_from_cache() click to toggle source

Return values from cached packages list - UNSYNC!!!

# File lib/repository_caching.rb, line 8
def get_packages_from_cache
  @packages_cache.values
end
initialization_cache() click to toggle source

Cache-related part of initialization

# File lib/repository_caching.rb, line 72
def initialization_cache
  #cached and parsed main XML MD file - repomd.xml
  @repomd_cache = nil
  #cached and parsed other XML documents
  @md_content_cache = { :primary => nil }
  #Repository Packages cache. Format: checksum => RPM::Package
  @packages_cache = {}
end
refresh_md_files_cache() click to toggle source

refreshing each md file cach

# File lib/repository_caching.rb, line 39
def refresh_md_files_cache
  @repomd_cache = read_repomd_doc
  @md_content_cache.keys.each { |type|
    @md_content_cache[type] = read_md_doc type.to_s
  }
end
refresh_packages_cache() click to toggle source

Actually check packages cache: create new one and fill it with old cache and newly created one

# File lib/repository_caching.rb, line 47
def refresh_packages_cache
    #save current cache state
    prev_cache = @packages_cache
    #clean current cache - used by other functions to refresh cache
    @packages_cache = {}
    @md_content_cache[:primary].each_element('/metadata/package') { |package_md|
      chksum = package_md.elements['checksum'].text
      if prev_cache[chksum]
        #get package from previous cache
        @packages_cache[chksum] = prev_cache[chksum]
      else
        #construct new one
        url = ''
        if package_md.elements['location'].attributes["xml:base"]
          url = URI::parse (package_md.elements['location'].attributes["xml:base"]+'/'+package_md.elements['location'].attributes["href"])
        else
          url = URI::parse ('file://' + @base_dir.path+'/'+package_md.elements['location'].attributes["href"])
        end
        @packages_cache[chksum] = RPM::Package.new url
      end
    }
    @logger.debug 'package cache refreshed'
end
repomd_cache_hit?() click to toggle source

true means 100% hit in cached repository state - UNSYNC!!! - used once

# File lib/repository_caching.rb, line 30
def repomd_cache_hit?
  if @repomd_cache.is_a? REXML::Document
    return read_repomd_doc.elements["/repomd/revision"].text == @repomd_cache.elements["/repomd/revision"].text
  else
    return false
  end
end
validate_packages_cache() click to toggle source

Check that current package list cache valid. if not - validate

# File lib/repository_caching.rb, line 13
def validate_packages_cache
  @logger.debug "validating packages cache"
  synchronize {
    if repomd_cache_hit?
      @logger.debug "MD cache hit"
      return true
    else
      refresh_md_files_cache
      refresh_packages_cache
      return true
    end
  }
end