send normalized keys to the cache backends so they do not need to man… #22215

Merged
merged 2 commits into from Nov 16, 2015

Conversation

Projects
None yet
4 participants
@grosser
Contributor

grosser commented Nov 7, 2015

…age this themselves

key manipulation is a recurring pattern in the cache stores (base + file + mem_cached) which makes the code less readable and mixes concerns

this moves all the key manipulation into a single method normalize_key and reuses that, which will also enable users to inherit or share logic better via modules since they no longer have to modify the key (escape_key or key_file_path or namespaced_key)

value
end
def decrement(name, amount = 1, options = nil) # :nodoc:
value = bypass_local_cache{super}
- set_cache_value(value, name, amount, options)

This comment has been minimized.

@grosser

grosser Nov 7, 2015

Contributor

cleaning this up ... passes amount but it is not being used ...

@grosser

grosser Nov 7, 2015

Contributor

cleaning this up ... passes amount but it is not being used ...

@grosser

This comment has been minimized.

Show comment
Hide comment
@grosser

grosser Nov 10, 2015

Contributor

@kaspth another one ... this did not get assigned to anyone ...

Contributor

grosser commented Nov 10, 2015

@kaspth another one ... this did not get assigned to anyone ...

@jeremy

This comment has been minimized.

Show comment
Hide comment
@jeremy

jeremy Nov 10, 2015

Member

API changes break any non-core cache store subclasses that override or call these methods.

Member

jeremy commented Nov 10, 2015

API changes break any non-core cache store subclasses that override or call these methods.

@grosser

This comment has been minimized.

Show comment
Hide comment
@grosser

grosser Nov 10, 2015

Contributor

so leave the method as namespaced_key so nobody that calls super gets hurt ?

Contributor

grosser commented Nov 10, 2015

so leave the method as namespaced_key so nobody that calls super gets hurt ?

@jeremy

This comment has been minimized.

Show comment
Hide comment
@jeremy

jeremy Nov 10, 2015

Member

And the callers of any of the methods that now require a namespaced/normalized key argument.

Member

jeremy commented Nov 10, 2015

And the callers of any of the methods that now require a namespaced/normalized key argument.

@grosser

This comment has been minimized.

Show comment
Hide comment
@grosser

grosser Nov 10, 2015

Contributor

Only private methods were changes, so this would only affect
users that do Rails.cache.send(:read_entry) ...

On Mon, Nov 9, 2015 at 8:51 PM, Jeremy Daer notifications@github.com
wrote:

And the callers of any of the methods that now require a
namespaced/normalized key argument.


Reply to this email directly or view it on GitHub
#22215 (comment).

Contributor

grosser commented Nov 10, 2015

Only private methods were changes, so this would only affect
users that do Rails.cache.send(:read_entry) ...

On Mon, Nov 9, 2015 at 8:51 PM, Jeremy Daer notifications@github.com
wrote:

And the callers of any of the methods that now require a
namespaced/normalized key argument.


Reply to this email directly or view it on GitHub
#22215 (comment).

@jeremy

This comment has been minimized.

Show comment
Hide comment
@jeremy

jeremy Nov 10, 2015

Member

The consumers of these API are other cache store subclasses. They call or super() to these boilerplate methods.

Member

jeremy commented Nov 10, 2015

The consumers of these API are other cache store subclasses. They call or super() to these boilerplate methods.

@grosser

This comment has been minimized.

Show comment
Hide comment
@grosser

grosser Nov 10, 2015

Contributor

so they would still work fine when renamed to normalize_parameters, right ?

Contributor

grosser commented Nov 10, 2015

so they would still work fine when renamed to normalize_parameters, right ?

@grosser

This comment has been minimized.

Show comment
Hide comment
@grosser

grosser Nov 10, 2015

Contributor

I added an alias for the old method, so there should be no fallout ... good to go ?

Contributor

grosser commented Nov 10, 2015

I added an alias for the old method, so there should be no fallout ... good to go ?

@grosser

This comment has been minimized.

Show comment
Hide comment
@grosser

grosser Nov 11, 2015

Contributor

rebased

@jeremy looking good ?

Contributor

grosser commented Nov 11, 2015

rebased

@jeremy looking good ?

@grosser

This comment has been minimized.

Show comment
Hide comment
@grosser

grosser Nov 12, 2015

Contributor

@rafaelfranca got 2 cents on that ?

Contributor

grosser commented Nov 12, 2015

@rafaelfranca got 2 cents on that ?

@grosser

This comment has been minimized.

Show comment
Hide comment
@grosser

grosser Nov 16, 2015

Contributor

@jeremy / @kaspth / @rafaelfranca ok to merge this ?

Contributor

grosser commented Nov 16, 2015

@jeremy / @kaspth / @rafaelfranca ok to merge this ?

@rafaelfranca

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Nov 16, 2015

Member

The API is being maintained by the alias so I think it is good. Thanks

Member

rafaelfranca commented Nov 16, 2015

The API is being maintained by the alias so I think it is good. Thanks

rafaelfranca added a commit that referenced this pull request Nov 16, 2015

Merge pull request #22215 from grosser/grosser/normalize_key
send normalized keys to the cache backends so they do not need to man…

@rafaelfranca rafaelfranca merged commit b58c37e into rails:master Nov 16, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
key = expanded_key(key)
namespace = options[:namespace] if options
prefix = namespace.is_a?(Proc) ? namespace.call : namespace
key = "#{prefix}:#{key}" if prefix
key
end
+ alias namespaced_key normalize_key

This comment has been minimized.

@kaspth

kaspth Nov 18, 2015

Member

This doesn't cover backwards compatibility. The file and mem cache stores changes break user written subclasses.

@kaspth

kaspth Nov 18, 2015

Member

This doesn't cover backwards compatibility. The file and mem cache stores changes break user written subclasses.

This comment has been minimized.

@grosser

grosser Nov 18, 2015

Contributor

user written subclasses of stores, not Cache itself, right ?

@grosser

grosser Nov 18, 2015

Contributor

user written subclasses of stores, not Cache itself, right ?

- File.atomic_write(file_name, cache_path) {|f| Marshal.dump(entry, f)}
+ return false if options[:unless_exist] && File.exist?(key)
+ ensure_cache_path(File.dirname(key))
+ File.atomic_write(key, cache_path) {|f| Marshal.dump(entry, f)}

This comment has been minimized.

@kaspth

kaspth Nov 18, 2015

Member

An example of the compat break: an overwritten write_entry wouldn't resolve the key to a file_name.

@kaspth

kaspth Nov 18, 2015

Member

An example of the compat break: an overwritten write_entry wouldn't resolve the key to a file_name.

@@ -118,7 +115,8 @@ def lock_file(file_name, &block) # :nodoc:
end
# Translate a key into a file path.
- def key_file_path(key)
+ def normalize_key(key, options)

This comment has been minimized.

@kaspth

kaspth Nov 18, 2015

Member

While this is private scope, we can't just remove the old method because subclasses can still freely call them.

@kaspth

kaspth Nov 18, 2015

Member

While this is private scope, we can't just remove the old method because subclasses can still freely call them.

This comment has been minimized.

@grosser

grosser Nov 18, 2015

Contributor

we could add a noop method for key_file_path ...

@grosser

grosser Nov 18, 2015

Contributor

we could add a noop method for key_file_path ...

@kaspth

This comment has been minimized.

Show comment
Hide comment
@kaspth

kaspth Nov 18, 2015

Member

Missed the conversation going on in #22205 (comment). Backing off 🤘

Member

kaspth commented Nov 18, 2015

Missed the conversation going on in #22205 (comment). Backing off 🤘

grosser added a commit to grosser/rails that referenced this pull request Nov 18, 2015

grosser added a commit to grosser/rails that referenced this pull request Nov 18, 2015

grosser added a commit to grosser/rails that referenced this pull request Nov 18, 2015

grosser added a commit to grosser/rails that referenced this pull request Nov 18, 2015

grosser added a commit to grosser/rails that referenced this pull request Nov 19, 2015

grosser added a commit to grosser/rails that referenced this pull request Nov 19, 2015

grosser added a commit to grosser/rails that referenced this pull request Nov 19, 2015

grosser added a commit to ccocchi/libmemcached_store that referenced this pull request Nov 20, 2015

@grosser grosser referenced this pull request in ccocchi/libmemcached_store Nov 20, 2015

Merged

use normalized keys everywhere to stay close to rails 5 #28

grosser added a commit to grosser/rails that referenced this pull request Nov 20, 2015

rafaelfranca added a commit that referenced this pull request Nov 20, 2015

Merge pull request #22332 from grosser/grosser/deprecation
add deprecations for a smooth transition after #22215

@francois-ferrandis francois-ferrandis referenced this pull request in influitive/apartment Feb 2, 2018

Closed

Apartment + Rails.cache + cache digest #73

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment