You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Stuart Maclean <ma...@mrvsys.com> on 2021/01/22 07:26:10 UTC

[jcs] Invalid Class Exception help needed

I am using JCS 2.2. I am an infrequent user of JCS, so please bear with 
me.  I have checked the mail list archives for past few years, couldn't 
find any answers to this q...

I have a cache region whose key type is say String and whose value type 
is some class C.  C is Serializable.

I use the cache, so objects of class C go into that region. The cache is 
backed by disk, so objects of class C end up in files.

C may then change, such that its serialVersionUID changes. If so, what I 
want to happen is that when I do a

C c = cache.get( "K" );

I would like to see the InvalidClassException, so that I can call

cache.clear()

and start over with the 'new' C objects.

But cache.get() doesn't throw such an error.  I always get a null result 
back, which means I can't distinguish this type of error from a simple 
cache miss (key not present), so I can't call the cache.clear().

Somewhere in the call stack, JCS is catching the error so that it 
doesn't propogate to user code?

Are there any api calls I can make to set the cache up so that it is 
cleared on this type of error?

Thanks

Stu


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [jcs] Invalid Class Exception help needed

Posted by Mat Jaggard <ma...@jaggard.org.uk>.
Hi, thanks for your question. I'm not a JCS expert by any means so I'm not
sure the answer to your question but I do have a question myself. What's
the reason for wanting to clear the cache in these cases rather than just
getting no result back so that you just refresh that value?

On Fri, 22 Jan 2021, 07:26 Stuart Maclean, <ma...@mrvsys.com> wrote:

> I am using JCS 2.2. I am an infrequent user of JCS, so please bear with
> me.  I have checked the mail list archives for past few years, couldn't
> find any answers to this q...
>
> I have a cache region whose key type is say String and whose value type
> is some class C.  C is Serializable.
>
> I use the cache, so objects of class C go into that region. The cache is
> backed by disk, so objects of class C end up in files.
>
> C may then change, such that its serialVersionUID changes. If so, what I
> want to happen is that when I do a
>
> C c = cache.get( "K" );
>
> I would like to see the InvalidClassException, so that I can call
>
> cache.clear()
>
> and start over with the 'new' C objects.
>
> But cache.get() doesn't throw such an error.  I always get a null result
> back, which means I can't distinguish this type of error from a simple
> cache miss (key not present), so I can't call the cache.clear().
>
> Somewhere in the call stack, JCS is catching the error so that it
> doesn't propogate to user code?
>
> Are there any api calls I can make to set the cache up so that it is
> cleared on this type of error?
>
> Thanks
>
> Stu
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Re: [jcs] Invalid Class Exception help needed

Posted by Thomas Vandahl <tv...@apache.org>.
Hi Stuart,

On 22.01.21 08:26, Stuart Maclean wrote:
> I have a cache region whose key type is say String and whose value type 
> is some class C.  C is Serializable.
> 
> I use the cache, so objects of class C go into that region. The cache is 
> backed by disk, so objects of class C end up in files.
> 
> C may then change, such that its serialVersionUID changes. If so, what I 
> want to happen is that when I do a

I guess what you are looking for happens in e.g. 
org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCache.readElement(K)

In this method, the ClassNotFoundException from deserialization is 
wrapped into an IOException. This exception is then caught by 
org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCache.processGet(K) 


In the catch clause, reset() is called, which clears the cache. So 
actually the behavior you are asking for actually should be there.

If you need more detailed control, you may provide your own 
org.apache.commons.jcs.engine.behavior.IElementSerializer and use the 
object validation features described in 
java.io.ObjectInputStream.registerValidation(ObjectInputValidation, int)

You will have to create the disk cache programmatically then, as the 
IElementSerializer cannot be set via configuration.

HTH
Bye, Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org