idealley / feathers-hooks-rediscache

Set of caching hooks and routes for feathersjs.
MIT License
38 stars 12 forks source link

Ability to specify cutsom keys (or paths) #37

Open DelfsEngineering opened 6 years ago

DelfsEngineering commented 6 years ago

I have a use case where my app responds to multiple domains.

As such the cache returns the same data for /somepath/someId for each of the domains. Is there a way to specify custom keys so I can add my own key in? perhaps in some before hook?

idealley commented 6 years ago

Is this different from your previous question (#35 )?

The main idea for me was to use the path of the api request as a "group" and the "slug" or the last segment of the request as the item key.

We could image a configuration option that would allow to use the full path as key. Let say now I have an api living at api.domain.com and an endpoint news that can also take an article slug news/:slug to return a single article.

This setting would generate a group key group-news a parent key news and an item key news for a single article an item only the key would be different something like the-slug-of-my-article. The domain is ignored all together.

Therefore we could imagine an option includeDomain: true that would generate a group key like group-domain.com-news like this you would know which domain saved the item in the cache and it would not break backward compatibility.

What do you think?

DelfsEngineering commented 6 years ago

Thanks for the reply, Yes that would work, Although I would think the domain inclusion is not common, but the ability to add data that would be part of the key would be valuable.

It would seem that a switch something like useCustomKey: true would also maintain compatibility also. I would think you would add the custom key in via an earlier hook. This would give any dev 100% control of groups and keys then ... ?

idealley commented 6 years ago

That makes sense. I agree the custom key would be a nice addition.

Would you have time to do a pull request? With an example of the earlier hook?