octo-online/robospice — pull request #277 by pdegand (2014-03-13 11:19:27+00:00)
Title: The cachePrefix generated by InFileObjectPersister is not suitable for correct cache manipulations

Hi,

This pull request fixes a bug on the InFileObjectPersister `getCachePrefix()` method.

Explanation: Im using a custom InFileObjectPersister named Foo, created by the FooFactory factory, to handle the Bar class.
I want to cache an instance of the Bar class with the "Bar1" cacheKey. The resulting filename where the cache will be stored is going to be `FooFactory_Foo_Foo1`.
Now, i want to cache another instance of the Bar class with the "Bar2" cacheKey. The resulting filename where the cache will be stored if going to be `FooFactory_Foo_Bar2`.
Now, using another instance of the Foo persister that handles the class John, I cache an instance of this John class with the cache key "John3". The resulting filename where the cache will be stored is going to be `FooFactory_Foo_John3`.
I finally have 3 cache files.

Now, the problem is : if I use later `SpiceManager.removeAllDataFromCache(Bar.class)` because i want to remove all the instances of the class Bar in my cache, the Foo persister will delete all the `FooFactory_Foo_*` cache file !
The deep reason is because the method `InFileObjectPersister.removeAllDataFromCache()` is filtering all the files in the cache folder based on the the `getCachePrefix()` and this method is only using the factory prefix and the persister simpleName to generate the cachePrefix, but not the handledClass simpleName.

To fix this behavior, I add the simpleClassName of the handledClass in the `InFileObjectPersister.getCachePrefix()` method.
Now, the cache file name will be `FooFactory_Foo_Bar_Bar1` and my `Foo.removeAllDataFromCache()` method will delete only the `FooFactory_Foo_Bar_*` files.

Relating unit test has been updated.
All tests pass.

Ready to merged.

Thanks for the (long) reading.
Pierre.

PS: I changed a small exception name in a JavaDoc tag because it was incorrect. My IDE showed it red !! :)