Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move delete failure detection to the cache fetcher. #296

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/identity_cache/cache_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ def write(key, value)
end

def delete(key)
@cache_backend.write(key, IdentityCache::DELETED, :expires_in => IdentityCache::DELETED_TTL.seconds)
result = @cache_backend.write(key, IdentityCache::DELETED, expires_in: IdentityCache::DELETED_TTL.seconds)
IdentityCache.logger.debug { "[IdentityCache] delete #{ result ? 'recorded' : 'failed' } for #{key}" }
Copy link
Contributor

@sirupsen sirupsen Oct 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason you're using blocks here is to avoid allocating the logging string unless you're at the debugging level?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just doing it the way we were doing it before, but I think that is probably the reason.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is the reason.

result
end

def clear
Expand Down
4 changes: 3 additions & 1 deletion lib/identity_cache/fallback_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ def write(key, value)
end

def delete(key)
@cache_backend.delete(key)
result = @cache_backend.delete(key)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it OK to do this in the fallback fetcher? What is the fallback fetcher?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback fetcher is just for compatibility for cache backends that don't support CAS operations. memcached_store is the only active support cache store that I know of that supports CAS.

The difference is that now it will just unconditionally log [IdentityCache] delete for #{key} with debug logging and won't attempt to indicate whether it failed or not.

IdentityCache.logger.debug { "[IdentityCache] delete for #{key}" }
result
end

def clear
Expand Down
4 changes: 1 addition & 3 deletions lib/identity_cache/memoized_cache_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def write(key, value)

def delete(key)
memoized_key_values.delete(key) if memoizing?
result = @cache_fetcher.delete(key)
IdentityCache.logger.debug { "[IdentityCache] delete #{ result ? 'recorded' : 'failed' } for #{key}" }
result
@cache_fetcher.delete(key)
end

def fetch(key)
Expand Down