You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-users@jakarta.apache.org by Enrique Rodríguez Lasterra <la...@javahispano.org> on 2006/09/25 01:06:26 UTC

null values/hasKey??

Hi all, maybe this is an stupid question, but i'm starting with JCS.

I want to put null values in the cache, and then ask if the key exist or not.

cacheAccess.put("key",null);
cacheAccess.get("key")==null
cacheAccess.get("non-existence-key")==null

is there any way to know if one key exists? Somthing like
cacheAccess.hasKey("key)::boolean

Regards, Enrique.

-- 
_______________________________
Enrique Rodriguez Lasterra
lasterra AT javahispano DOT org
http://www.javahispano.org
Asociación sin ánimo de lucro sobre java
Spanish non profit association about java

---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


Re: null values/hasKey??

Posted by Enrique Rodríguez Lasterra <la...@javahispano.org>.
One problem with the workarund is that stats will be wrong, becouse if
i waat to check if one key exists, i have to call to
cacheaccess.get(key), and this will add one point to the stats
hitCount/missCountNotFound.

Regards, enrique.

2006/9/25, Enrique Rodríguez Lasterra <la...@javahispano.org>:
> Hi al, thanks for the workaround, is a good idea, but i think that a
> cache should have null values.
>
> Regards, Enrique.
>
> 2006/9/25, Al Forbes <fo...@googlemail.com>:
> > Hi,
> >
> > I can't remember where it was written, but you cannot add null to the cache.
> >
> > Best is to create an empty object of some type and check this object, or a
> > field in an object. This should be in the FAQ as I'm sure many people have
> > hit the same issue.
> >
> > Regards
> > Al
> >
> > On 25/09/06, Enrique Rodríguez Lasterra <la...@javahispano.org> wrote:
> > >
> > > Hi all, maybe this is an stupid question, but i'm starting with JCS.
> > >
> > > I want to put null values in the cache, and then ask if the key exist or
> > > not.
> > >
> > > cacheAccess.put("key",null);
> > > cacheAccess.get("key")==null
> > > cacheAccess.get("non-existence-key")==null
> > >
> > > is there any way to know if one key exists? Somthing like
> > > cacheAccess.hasKey("key)::boolean
> > >
> > > Regards, Enrique.
> > >
> > > --
> > > _______________________________
> > > Enrique Rodriguez Lasterra
> > > lasterra AT javahispano DOT org
> > > http://www.javahispano.org
> > > Asociación sin ánimo de lucro sobre java
> > > Spanish non profit association about java
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> > >
> > >
> >
> >
>
>
> --
> _______________________________
> Enrique Rodriguez Lasterra
> lasterra AT javahispano DOT org
> http://www.javahispano.org
> Asociación sin ánimo de lucro sobre java
> Spanish non profit association about java
>


-- 
_______________________________
Enrique Rodriguez Lasterra
lasterra AT javahispano DOT org
http://www.javahispano.org
Asociación sin ánimo de lucro sobre java
Spanish non profit association about java

---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


Proposed changes in JCS cache to shutdown gracefully

Posted by Ma...@equifax.com.



Aaron, all,

Here is my proposal of what needs to be changed in JCS cache to gracefully
handle remote cache shutdown when using TCP lateral cache & UDP Discovery
mechanism.

Issue:
When shutting down one JVM, all other JVMs start reporting lateral cache
errors because they cannot connect to the cache that was just shut down.

Proposed solution:
- add a new message type to UDPDiscoveryMessage.java:
    /*
     * Added to handle graceful shutdowns of remote caches
     */
    public static final int SHUTDOWN_BROADCAST = 2;

- modify UDPDiscoveryService to send this message when instance is shutting
down (in the ShutdownObserver#shutdown() method)
- modify code to handle shutdown messages correctly (remove
LateralCacheNoWait from noWaits in the LateralCacheNoWaitFacade)

Attached is source code of all files that I had to modify to get this to
work:
(See attached file: LateralCacheNoWaitFacade.java)
(
added   public boolean removeNoWait( LateralCacheNoWait noWait ) method
)

(See attached file: LateralTCPCacheManager.java)
(
added   public static LateralTCPCacheManager removeInstance(
ITCPLateralCacheAttributes lca, ICompositeCacheManager cacheMgr ) method,
)

(See attached file: UDPDiscoveryMessage.java)
(
added new message type:
    /*
     * Added to handle graceful shutdowns of remote caches
     */
    public static final int SHUTDOWN_BROADCAST = 2;
)

(See attached file: UDPDiscoveryService.java)
(
modified the   public void shutdown() method,
added   protected void serviceShutdownBroadcast() method,
added   protected void removeNoWait( LateralCacheNoWait noWait )
)
(See attached file: UDPDiscoverySender.java)
(
added   public void shutdownBroadcast( String host, int port, ArrayList
cacheNames ) throws IOException method
)

(See attached file: UDPDiscoveryReceiver.java)
(
modified         public void run() method of MessageHandler
)

Is there any way I can get these changes incorporated into "official" JCS
cache source code?

Thanks,

Marek Cyzio
Equifax
(770)740-6610
Marek.Cyzio@equifax.com



This message contains information from Equifax Inc. which may be
confidential and privileged.  If you are not an intended recipient, please
refrain from any disclosure, copying, distribution or use of this
information and note that such actions are prohibited.  If you have
received this transmission in error, please notify by e-mail
postmaster@equifax.com.

Re: null values/hasKey??

Posted by Aaron Smuts <as...@yahoo.com>.
OK.  I use the null object pattern when I don't want
to continually go remote or to a database or to a
webservice for data that doesn't exist.  

For instance, let's say that I'm building an client to
an air shopping service that runs in a different
system (different db, org unit, etc.).  I get back
city codes that I then need to decode--translate into
a city name or a city id in my database.  Sometimes I
might get back bad city codes or codes that don't
correspond to cities in my db.  There are other cases
that are more acceptable than cities, such as
equipment codes.     

I don't want to keep going from the local to the
remote cache and then to the database looking for the
decoded values for stuff that doesn't exist.  I could
see the same value 1000 or more times in a single shop
response.  I wouldn't want to keep doing 1000 extra
queries for nothing for every shop.  That would be
awful.  Bad data or a missing item could take down the
system at high loads.

The solution is to put a special object in the cache
that represents a Null Object.  Rather than putting in
a global null object, I put in a special instance of
the type of object that I'm caching in that region.  I
don't want to mix types in the collection.  

So, when I get an item out of the cache I check to see
(1) if it is equal to the null instance.  If so, I
return null.  (2) If it is null, then I know that I
haven't seen it before and I should try the database. 
(3) If it is not null and not equal to the null
instance, I return it.

The cache cannot do this for you.  This has to be done
programatically at the cache client.  I have a layer
in my application stack that handles caching.  

I develop service in these layers, which also
correspond to separate projects (i.e. separate
artifacts).  Clean project layers and SOA make for a
very nice system.  In my current app I have over 20
deployable application projects (collections of
services) that all run in their own Tomcat instances
(6 or so to a machine) and around 30 projects in total
(10 or so are non deployable), all built and managed
using maven and wired together with Spring (only using
the bean factory).  

Every web service has these layers and more:

REST Service Controller 
(http into the framework; XML response generation via
velocity or jibx; calls the logical service to do the
real work; this lives in a deployable application's
project)
   |
   v
Logical Service 
(can talk to multiple services and managers)
   |
   V
Manager 
(Caching Facade; can talk to only one DAO and no other
managers; transforms objects from DAOs to local return
types)
   |
   V
DAO 
(direct sql) 
or Web Service Client 
(velocity request generation; jibx parsing)


The Null Object pattern is implemented in the manager
layer, since that is the only place where caching
occurs.

Cheers,

Aaron


--- Enrique Rodríguez Lasterra
<la...@javahispano.org> wrote:

> i will try to explain it, but my english is not as
> good as it should be :-(
> 
> I want to use JCS on my SDO/jsr235 persistence
> system. When i make a
> "select * fro  table where primaryKey = X" o could
> get a table row or
> not, but i want to store the result on the cache.
> 
> If I repeat the select, i want to check if JCS has
> the table row
> stored on it by its primaryKey. If it is stored, but
> its value is
> null, it should response with null and it should
> counted as a hit
> count, becouse null is the value i put on the cache.
> 
> if the cache does not kave the primaryKey stored, i
> should get the row
> from database.
> 
> So, from my point of view, is not the same store
> null values or leave
> cache without nulls.
> 
> We the workaround, everything run perfectly but the
> stats of
> hitCount/missCount aren't real.
> 
> Regards, Enrique.
> 
> 2006/10/7, Thomas Vandahl <tv...@apache.org>:
> > Enrique Rodríguez Lasterra wrote:
> > > Hi al, thanks for the workaround, is a good
> idea, but i think that a
> > > cache should have null values.
> >
> > What for? When I try to get some object for a key
> that does not exist, I
> > get null anyway. And (responding to your next
> posting) yes, this is
> > indeed a cache miss which should be counted as
> such.
> >
> > Bye, Thomas.
> >
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> jcs-users-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> jcs-users-help@jakarta.apache.org
> >
> >
> 
> 
> -- 
> _______________________________
> Enrique Rodriguez Lasterra
> lasterra AT javahispano DOT org
> http://www.javahispano.org
> Asociación sin ánimo de lucro sobre java
> Spanish non profit association about java
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> jcs-users-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> jcs-users-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


Re: null values/hasKey??

Posted by Enrique Rodríguez Lasterra <la...@javahispano.org>.
i will try to explain it, but my english is not as good as it should be :-(

I want to use JCS on my SDO/jsr235 persistence system. When i make a
"select * fro  table where primaryKey = X" o could get a table row or
not, but i want to store the result on the cache.

If I repeat the select, i want to check if JCS has the table row
stored on it by its primaryKey. If it is stored, but its value is
null, it should response with null and it should counted as a hit
count, becouse null is the value i put on the cache.

if the cache does not kave the primaryKey stored, i should get the row
from database.

So, from my point of view, is not the same store null values or leave
cache without nulls.

We the workaround, everything run perfectly but the stats of
hitCount/missCount aren't real.

Regards, Enrique.

2006/10/7, Thomas Vandahl <tv...@apache.org>:
> Enrique Rodríguez Lasterra wrote:
> > Hi al, thanks for the workaround, is a good idea, but i think that a
> > cache should have null values.
>
> What for? When I try to get some object for a key that does not exist, I
> get null anyway. And (responding to your next posting) yes, this is
> indeed a cache miss which should be counted as such.
>
> Bye, Thomas.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jcs-users-help@jakarta.apache.org
>
>


-- 
_______________________________
Enrique Rodriguez Lasterra
lasterra AT javahispano DOT org
http://www.javahispano.org
Asociación sin ánimo de lucro sobre java
Spanish non profit association about java

---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


Re: null values/hasKey??

Posted by Thomas Vandahl <tv...@apache.org>.
Enrique Rodríguez Lasterra wrote:
> Hi al, thanks for the workaround, is a good idea, but i think that a
> cache should have null values.

What for? When I try to get some object for a key that does not exist, I 
get null anyway. And (responding to your next posting) yes, this is 
indeed a cache miss which should be counted as such.

Bye, Thomas.


---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


Re: null values/hasKey??

Posted by Enrique Rodríguez Lasterra <la...@javahispano.org>.
Hi al, thanks for the workaround, is a good idea, but i think that a
cache should have null values.

Regards, Enrique.

2006/9/25, Al Forbes <fo...@googlemail.com>:
> Hi,
>
> I can't remember where it was written, but you cannot add null to the cache.
>
> Best is to create an empty object of some type and check this object, or a
> field in an object. This should be in the FAQ as I'm sure many people have
> hit the same issue.
>
> Regards
> Al
>
> On 25/09/06, Enrique Rodríguez Lasterra <la...@javahispano.org> wrote:
> >
> > Hi all, maybe this is an stupid question, but i'm starting with JCS.
> >
> > I want to put null values in the cache, and then ask if the key exist or
> > not.
> >
> > cacheAccess.put("key",null);
> > cacheAccess.get("key")==null
> > cacheAccess.get("non-existence-key")==null
> >
> > is there any way to know if one key exists? Somthing like
> > cacheAccess.hasKey("key)::boolean
> >
> > Regards, Enrique.
> >
> > --
> > _______________________________
> > Enrique Rodriguez Lasterra
> > lasterra AT javahispano DOT org
> > http://www.javahispano.org
> > Asociación sin ánimo de lucro sobre java
> > Spanish non profit association about java
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> >
> >
>
>


-- 
_______________________________
Enrique Rodriguez Lasterra
lasterra AT javahispano DOT org
http://www.javahispano.org
Asociación sin ánimo de lucro sobre java
Spanish non profit association about java

---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


Re: null values/hasKey??

Posted by Al Forbes <fo...@googlemail.com>.
Hi,

I can't remember where it was written, but you cannot add null to the cache.

Best is to create an empty object of some type and check this object, or a
field in an object. This should be in the FAQ as I'm sure many people have
hit the same issue.

Regards
Al

On 25/09/06, Enrique Rodríguez Lasterra <la...@javahispano.org> wrote:
>
> Hi all, maybe this is an stupid question, but i'm starting with JCS.
>
> I want to put null values in the cache, and then ask if the key exist or
> not.
>
> cacheAccess.put("key",null);
> cacheAccess.get("key")==null
> cacheAccess.get("non-existence-key")==null
>
> is there any way to know if one key exists? Somthing like
> cacheAccess.hasKey("key)::boolean
>
> Regards, Enrique.
>
> --
> _______________________________
> Enrique Rodriguez Lasterra
> lasterra AT javahispano DOT org
> http://www.javahispano.org
> Asociación sin ánimo de lucro sobre java
> Spanish non profit association about java
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jcs-users-help@jakarta.apache.org
>
>