feathers-hooks-rediscache icon indicating copy to clipboard operation
feathers-hooks-rediscache copied to clipboard

Ability to specify cutsom keys (or paths)

Open DelfsEngineering opened this issue 6 years ago • 3 comments

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?

DelfsEngineering avatar May 30 '18 18:05 DelfsEngineering

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?

idealley avatar Jun 02 '18 13:06 idealley

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 ... ?

DelfsEngineering avatar Jun 05 '18 11:06 DelfsEngineering

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?

idealley avatar Jun 05 '18 12:06 idealley