In which layer is the cache implemented?

I am developing the Rest API using the Service Stack framework. All layers are separated, so we can do DAL mocks to test the logic level.

I am setting up a cache with control inversion:

container.Register<ICacheClient>(new MemoryCacheClient());

Where MemoryCacheClient is a simple class that implements ICacheClient several ways.

And here is the question: what is the best layer for including a call in the cache through this inversion of control?

  • It may be in BLL, but would it not be a problem for unit tests?

  • Could it be in DAL, knowing that I have to lose the IOC? And in this case, I will depend on the web server cache, which may be wrong.

  • It can be in the web interface, knowing that I can have some logic and even lose some functions?

  • Could this be between the web interface and the BLL, creating a new layer?

I searched and read some articles a lot, but no luck:

Thanks x

+7
source share
1 answer

Your caching does not have to be in any layer. You can keep it external from your business logic and data access logic by wrapping calls that will use caching in the decorated method and setting up the use of the caching decorator in the IoC container.

I did not do this specifically with ServiceStack, but the template is well documented:

+5
source

All Articles