Skip to content

Commit

Permalink
Flush only with changes
Browse files Browse the repository at this point in the history
  • Loading branch information
over committed Jul 14, 2015
1 parent 0fbab59 commit 33b837e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/copycopter_client/cache.rb
Expand Up @@ -20,6 +20,7 @@ def initialize(client, options)
@mutex = Mutex.new
@queued = {}
@started = false
@cache_was_changed = false
end

# Returns content for the given blurb.
Expand All @@ -34,6 +35,7 @@ def [](key)
# @param key [String] the key of the blurb to update
# @param value [String] the new contents of the blurb
def []=(key, value)
@cache_was_changed = false
lock { @queued[key] = value }
end

Expand Down Expand Up @@ -88,11 +90,16 @@ def wait_for_download
end

def flush
with_queued_changes do |queued|
client.upload queued
if @cache_was_changed
begin
with_queued_changes do |queued|
client.upload queued
end
@cache_was_changed = false
rescue ConnectionError => error
logger.error error.message
end
end
rescue ConnectionError => error
logger.error error.message
end

def download
Expand Down

0 comments on commit 33b837e

Please sign in to comment.