module DistributedCache
Public Class Methods
config()
click to toggle source
# File lib/distributed_cache.rb, line 9 def self.config @@config ||= DistributedCache::Config.new end
configure() { |config| ... }
click to toggle source
# File lib/distributed_cache.rb, line 13 def self.configure yield self.config end
sync()
click to toggle source
# File lib/distributed_cache.rb, line 47 def self.sync self.config.file_servers.each do |server| DistributedCache::Utils.rsync server end end
update_local_cache(cache_name)
click to toggle source
# File lib/distributed_cache.rb, line 43 def self.update_local_cache(cache_name) DistributedCache::Bundle.new(self.config, cache_name).install end
update_remote_cache(klass)
click to toggle source
in order to cache a klass it must respond to cache_name - this is the directory in the base cache directory where the new cache files are created, ex: applications cache_version - this is the version of the klass being saved, guards against changes to model where new fields are added or removed ex: 20130731 update_cache - this method caches data to disk, it is passed the manifest object. This can be used to store things like the last_id. So on later runs you can just pull the new records out of the database.
ex models = self.where("id > #{manifest['last_id'].to_i").all.each { |m| m.cache_model }; manifest['last_id'] = models.map(&:id).max
# File lib/distributed_cache.rb, line 22 def self.update_remote_cache(klass) raise "cache_dir not configured" if self.config.cache_dir.nil? raise "bundle_dir not configured" if self.config.bundle_dir.nil? manifest = DistributedCache::Manifest.new self.config, klass.cache_name, klass.cache_version DistributedCache::Utils.rm_rf manifest.cache_dir FileUtils.mkdir_p manifest.cache_dir return unless klass.update_cache(manifest) tar_name = "#{manifest.cache_path}/#{klass.cache_name}-#{manifest.files.size + 1}.#{manifest.full? ? 'tgz' : 'tar'}" tar_file = "#{config.bundle_dir}/#{tar_name}" Dir.chdir(config.cache_dir) do DistributedCache::Utils.tar tar_file, klass.cache_name end manifest.add_file tar_name, tar_file manifest.save manifest.update_latest_bundle_dir end