3 Replies Latest reply on Mar 8, 2006 12:59 PM by cptnkirk

    Performance Tuning for rarely changed data

    andy.2003

      Hello,

      I'm thinking about how to access rarely changed data the right way.

      An example: I store categories in the database; they may change once a week.

      So normally I would store them in Application Scope, but as I triggered out, there is no easy way to invalidate the Application scope - in case of a change (only if I call a method to reinitialize (@create) the Component).

      Now my second thought was about using Hibernate cache to store the categories in Memory. But I don?t really know how to handle the update.

      Is there a design pattern for this problem and what is the better approach (Application Scope or cache)?

      Important is, that the categories are not reloaded every request but that they are updated if they were changed.

        • 1. Re: Performance Tuning for rarely changed data

          How are your categories being updated? If your app is the only one that writes to the DB via Hibernate, then using a long lived Hibernate cache probably makes sense. If however you need to handle out of band writes, you'll need some way for the writing process to trigger an invalidation/reload of your category cache. You could write a web service here, or have some other communication mechanism. Otherwise you'll need to check on every request.

          If getting it close is good enough, you could use a Hibernate cache that reloads every so often (timeout is configurable). There is risk that you'll be out of date, but you'll only be at most 1 time period out of date. Make this an hour, a day, whatever and you've cut down DB requests significantly.

          -Jim

          • 2. Re: Performance Tuning for rarely changed data
            andy.2003

            Hello Jim,

            thank you for your reply!

            I got an userfront and an adminfront, the userfront should only read the categories and the admin should also be able to change the categories.

            How can I setup a timeout for only one entity? And can I give an entity more than one cache startegies?

            Anyway, I'm still intrested in if there is a possibility to invalidate the Application scope (maybe a seam core function)

            - Andreas

            • 3. Re: Performance Tuning for rarely changed data

              Couldn't you simply outject a new component to replace your stale application scoped guy? You could also have a smarter component that could poll and refresh on a regular basis. Not exactly sure what the invalidation question is.

              There is a lot more documentation on Hibernate and its configuration options. You can set cache options per class or collection mapping. To drastically reduce your DB hits, you could mark the class read-only and then specify the timeout by which it refreshes the cache anyway. Don't have the exact notation for specifying the time out, but the Hibernate docs or forums should.

              -Jim