R – Creating repositories with spring.net

spring.net

I'm creating my repositories with spring.net. However, I'm wondering what the lifetime is of these objects. In my repositories, objects that are retrieved from the database are cached in a registry. But this should only happen for a single server call. Can you specify in spring.net configuration that the objects should be created for each call to the server.

I guess singleton=false doesn't do it for me, as this will create a new Repository everytime, even in the same thread.

Best Answer

This is a complicated question, because the design of the cache and registry comes into play. It sounds like the lifetime of the persistent objects will be controlled by the registry, since it will be maintaining references.

So there are a few things to ask:

  1. Which object owns the cache? The repository, the service, or something else?
  2. How are you invalidating the cache? Is it keeping track when persistent objects are updated?
  3. What's the timeout value for the session in which the objects are created? How would an invalidated session be communicated to the cache?
  4. When you say "registry", do you mean "Windows registry"? (god forbid, please so "no".)

In Spring for Java EE, one usually gets configurable caching with Hibernate and EhCache. If you use the Spring JDBC template you have to write it yourself. What implementation are you using for your repositories?

Related Topic