I know this has been discussed somewhat in this newgroup but I haven't
seen any real conclusion on what I am going to suggest here.

It seems to me that stateless beans can be a good choice for caching
database data under certain circumstances.  One great thing about a
stateless bean is that they provide automatic failover in a clustered
environment.  Also stateless beans are not passivated. Here are the
conditions under which I think stateless beans can be used for caching.

1. Going to the database on each call to get the data would be
prohibitively  expensive.
2. You are willing to have multiple copies of the cache around.  Or if
the server allows you to set the maximum number of beans then you could
have a singleton.
3.  The number of updates to the database is relatively small and it is
easy to update the cache if the nature of the updates is known.

The idea is that you would have multiple copies of the cache in each
stateless bean created by the container. To implement this you would do
the following.

Each stateless bean maintains a sequence number.  The database maintains
a table which contains the latest updates.  Whenever an update is made
to the database which can affect the cache an entry should be made into
that table.  Each entry has a sequence number.  When a call is made to
the stateless bean it gets all the new updates from the database since
it's last call and appropriately updates the cache.

Imagine a case where no updates are made.  Then this would certainly be
very efficient.

One question I have is whether most EJB servers allow you to specify how
many stateless session beans are created.  It still would work without
that but it would be nice to be able to specify it.  On a side note, if
one could specify that at most one stateless bean should be created then
wouldn't that provide a singleton?  If that is the case then you could
skip the update checking if you force all updates to go through the one
stateless session bean.

What do you think?  Am I missing something here?

Sidebar:  Stateless Session Beans and singletons.
It seems to me that if you can specify that at most one stateless bean
should be created then you could create a singleton.  This relies on the
fact that the container will serialize calls to the stateless bean.

dan

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to