ICacheSpecificationBuilder - #161
Conversation
|
Hi @vittorelli, Thank you. I do like this. We're not including anything specific, but we're providing a mechanism for users to handle it by themselves. Your usage is nice too. To be honest, keeping app-wide mutable shared state is always fishy :) Yea, the concurrent dictionary is considered thread-safe, but not all methods. Having your own base specification which will include the state might be a better solution, but it requires a bit more work. @ardalis if you don't have any comments, let's merge this. |
Don't know why I didn't think of that. Way better, thanks! :-) |
|
I love it; let's do it! Any chance we can get a docs PR with some usage examples, too? |
|
I'll see what I can do about the docs :-) |
A small change to the
SpecificationBuilderExtensions.EnableCachebuilder method in order to allow developers to create their own extension methods for customized caching implementations.I've been using Spefications throughout several different projects and am a huge fan. We've recently added support for caching in our repositories and I've refactored the code so it integrates with Specification. A requirement in our project was to have some expiration date on the cache, which isn't possible with the current method signatures. I saw two possibilities:
SpecificationBuilderExtensions.EnableCache.The liked the first option better, but soon realised that my requirements wouldn't nessecarily match those of other developers, and I didn't like the idea of creating too many new methods to support different needs in caching behaviour (absolute expiration, sliding windows, tokens, ....).
So I've gone with the second possibility.
The main idea of this pull request is to constrain the usage of extension methods one may create to facilitate custom caching needs in projects that consume Ardalis.Specification. This idea might also be extended to other builder methods.
What do you guys think?
Example on how I'm using the ICacheSpecificationBuilder