How do I create a cache object?


Performance and scalability: How do I create a cache object?

  1. How do I create a cache object? (8 messages)

    I have an application using JBoss 3.0.4 implementing a session facade pattern in which all our entity beans are referenced by session bean methods. Our tomcat web client calls only on the session bean methods.

    Problem is, I am fetching and computing the same set of data over and over again for each user that logs into the system. For example, we have a conference enrollment application. It has a schedule with fixed dates, and times. The dates and times never change, yet for each user that logs on, we have to go to the session layer and then the entity layer to make the calls necessary to return the conference schedule of dates and times.

    When several hundred users log in, the overhead of computing dates and times is so high - for EACH USER --that the system just stops with a huge backlog of SQL queries to the DB and eventually 1 of two things happens: 1) the DB is overwhelmed and blows through some storage limit, or 2) the system response drops to 0 until enough frustrated users go away thus allowing the system to recover and process the remaining queries.

    How can I make a cache object, with a couple of HashMaps in it, that will be created and filled once and that the session beans can read data from? Is this a stateful bean? I didn't think so, because there is no conversational state and the state never changes. Maybe I am wrong.

    Any help is kindly appreciated.


    Threaded Messages (8)

  2. How do I create a cache object?[ Go to top ]

    Check out this article at JavaWorld discussing about implementing a caching framework:
  3. How do I create a cache object?[ Go to top ]

    You might want to have a look at one of the caching products that are available. Although your requirements sounds quite straightforward, plenty of people have run into trouble trying to implement caching themselves in session beans.

    My own employer, Isocra, have a caching product called livestore, which caches at the JDBC level, and is therefore probably the easiest to plug into an already-written application. Alternatives I know of: Tangosol have a product called Coherence, which helps run TheServerSide. GemStone also have a caching product, and have some kind of relationship with JBoss.

    Simon Kinahan, Isocra Ltd
  4. How do I create a cache object?[ Go to top ]

    well, to start with, it is very hard to do caching objects. now, if your data doesn't change, or in other words, if your reads are much higher then writes, then it should be easy.
     I don't know about your project, however, this can be doen by creating an Object that will hold the data for you. you can implement this object they way you want. you can have a HashMap inside a HashMap implemention, or anything you want. the only method you need is getObject(int PK). this will return the value for the given PK, and if the value is not in the cache, it will go and get it form the DB and store it in the chache. This object will nont work if your data is changing. now make sure that there is one object of the chache in the JVM. you can do this by makeing the constructor of your object as private. this is an example :

      private static Cache instance;

    public static Cache getInstance()
    if (instance == null)
    instance = new Cache();
    return instance;

      private Cache() {}

     now this is the simplest way you can do caching, it works fine if you have one JVM and no writing. however, if you want to run your appliction in more then one JVM, and you need to write, then you should use CMP. you can create a "conference enrollment" CMP and the EJB server will take care of caching for you. I guess this is the reason why we use EJB, we need chaching and we don't want to implement it! and finally, if none of what I said works with you, you might really consider Simon Kinahan post. there are a number of good chaching products out there, and livestore as far as I know, is the easiest product because it works at the JDBC level.
     I am sorry for my English, but I hope I helped you in your problem. and you have a great day

    Adel Alrashidi
  5. How do I create a cache object?[ Go to top ]

    This question is very vague, and here is why:

    - if you are concerned with caching data, many databases will often optimize and cache queries. It's not the most efficient route since you still have to connect to the database and possibly make a remote call, but you won't have to do any extra coding at all either.

    - you could cache at the ejb level. In this case, it is also done for you. Some containers do it better than others, however. This still means that you have to use jndi and use the remote/local interface, but it's better than caching queries.

    - You could use caching tags, but this ties to jsp. If you are using jsp anyway, than this is a very good solution.

    - Use normal java objects at the web-tier level or maybe servlet filters. This makes it better to use for more presentation formats than the previous suggestion.

    - You could also generate static html pages and only re-generate them when you make changes (assuming you are doing more reads than writes)
  6. How do I create a cache object?[ Go to top ]

    If you want to cache in the web tier, do it the Business Delegate layer - this is one of its important potential features. This way caching is more transparent - if you decide later to move the cache to another tier, your web client code will not be affected.
  7. How do I create a cache object?[ Go to top ]

    We have used a businessdelegate object as mentioned. We use EJBHomeFactory to lookup and cache home references to home objects. One webpage has dropdown lists with a lot of data that we do not want to fetch from the database each time. The dropdownlists contains products, country, currency, etc. Instead we cache this data in collections in this delegate object. Works fine.

  8. How do I create a cache object?[ Go to top ]

    To avoid an overload of db connections and retrievals, as opposed to any type of in-process caching, I would recommend caching out of process in a centralized repository. By caching out of process you can avoid wasting memory, tying up CPU resources, and issues with cache synchronization and garbage collection. A company called Chutney Technologies is pioneering this new form of out of process caching that eliminates the above issues while allowing object caching at any layer of the application; ie. session objects, EJBs, html fragments, etc.
  9. How do I create a cache object?[ Go to top ]

    Hi Joe,

    Given your situation I would point you in the direction of Tangosol's Coherence in-memory clustered caching product. Coherence 2.0 introduces the ability to query against the cache itself. With a distributed cache, the query processing becomes extremely scalable, allowing the queries to be processed across the entire cluster. The query mechanism is fully programmable and customizable, and includes full support for indexing and cost-based optimizations.

    Tangosol offers free Evaluation and Development licenses. Production license fees, including bulk purchase discounts, are published on our site.

    Rob Misek
    Coherence: Easily share live data across a cluster!