Skip to content

Commit

Permalink
Only log cache write if the operation was successful
Browse files Browse the repository at this point in the history
Signed-off-by: David Souza <david@souza.net>
  • Loading branch information
Morgan Brown authored and davidsouza committed Apr 5, 2012
1 parent 560cc08 commit 1b5a323
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/cached_resource/caching.rb
Expand Up @@ -64,11 +64,12 @@ def cache_read(key)
# The key is processed to make sure it is valid.
def cache_write(key, object)
key = cache_key(Array(key)) unless key.is_a? String
cached_resource.logger.info("#{CachedResource::Configuration::LOGGER_PREFIX} WRITE #{key}")
cached_resource.cache.write(key, object, :expires_in => cached_resource.ttl)
result = cached_resource.cache.write(key, object, :expires_in => cached_resource.ttl)
result && cached_resource.logger.info("#{CachedResource::Configuration::LOGGER_PREFIX} WRITE #{key}")
result
end

# generate the request cache key
# Generate the request cache key.
def cache_key(*arguments)
"#{name.parameterize.gsub("-", "/")}/#{arguments.join('/')}".downcase
end
Expand Down

0 comments on commit 1b5a323

Please sign in to comment.