开发者

Making ehcache read-write for test code and read-only for production code

I would like to annotate many of my Hibernate entities that contain reference data and/or开发者_开发百科 configuration data with

@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)

However, my JUnit tests are setting up and tearing down some of this reference/configuration data using the Hibernate entities. Is there a recommended way of having entities be read-write during test setup and teardown but read-only for production code?

Two of my immediate thoughts for non-ideal workarounds are:

  • Using NONSTRICT_READ_WRITE, but I am not sure what the hidden downsides are.
  • Creating subclassed entities in my test code to override the read-only cache annotation.

Any recommendations on the cleanest way to handle this?

(Note: Project uses maven.)


Answering my own question:

Using NON_STRICT_READ_WRITE is a reasonable solution that has most of the benefits of READ_ONLY, but allows your test code to insert and update entities.

Remember to evict any cached items during test setup to ensure you aren't reading stale test data. (e.g. evictQueries()).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜