I have a DataAccess Class and it has a reference to a an interface. The interface represents the caching strategy to use.

I would like that the caching strategy has something like an initalize() method that fills the cache on startup. However that method would then require the DataAccess class to get access to the data and I end up with a cross-reference.

I also don't want to "pollute" the interface with setter methods because not all implementations would need it. Also preferably no setter in DataAccess class as i want all fields to be final.

I could create an additional layer that calls into dataaccess?

Other ideas?

有帮助吗?

解决方案

You should wrap the DataAccess class with a Cache lookup class which only accesses the DataAccess class if it cannot get the data from its internal cache. Like you've mentioned, this would consist of an extra layer, but depending on the way you implement it, it can be transparent to the application code (for example, by the use of AOP).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top