Announcement Announcement Module
Collapse
No announcement yet.
Simple cacheing idea Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple cacheing idea

    I'm not wholly comfortable with Spring AOP yet and was hoping someone might point me to the simplest way of doing the following, which strikes me as a likely candidate for the benefits of AOP.

    I'm working on a web application which has lots of different business objects, and in very many cases there is a need to provide popups of, say, all countries when adding/editing organisations, that kind of thing. That is, a collection of any object might be used as a choice list for any other object. Now, obviously if we do a select from the database every time, this will bring the system to its knees. Yet if we use a cache, we have to be certain that nothing has changed in the source data since we populated the cache.

    What I would like to do is to intercept all method calls of 'storeXXX' and 'deleteXXX' in the DAO layer and update a row in the db to indicate that, e.g., the countries data was last modified at this time. Similarly, I would like to intercept all calls to 'listXXX' (the methods which will give me the choice lists), check in a cache (maybe EHCache, maybe a simple LinkedHashMap) to get the timestamp of this cache copy, look in the database to see if the sata has been modified since, and if it has, refresh the cache, otherwise use the cache entry.

    I appreciate that the Wanghey cache does something not a million miles away, but I want something really simple for this. Any pointers as to what interfaces I need to implement?

    TIA

  • #2
    You are correct in that this can be done quite simply. The only interface you need to implement is MethodInterceptor so you can intercept the calls to your business methods and then update or query the cache as appropriate. How you implement the cache is purely up to you, although EHCache is a good candidate because you can easily configure it in Spring.

    You might want to create two MethodInterceptors, one to handle cache query and the other to handle cache update. Then use pointcuts to match these MethodInterceptors to the specific methods you are after. You will probably find the regular expression-based pointcuts are suitable for your requirement.

    Rob

    Comment


    • #3
      Originally posted by robh
      You will probably find the regular expression-based pointcuts are suitable for your requirement.
      Thanks. Is there a simple example of this floating around anywhere? The examples I looked at were a little more elaborate than I needed.

      Comment


      • #4
        Not that I know of. If you want to post what you have done once it is ready, I'll check it and see if it could be simplified.

        Rob

        Comment

        Working...
        X