I'd like to use cache not only to store map tiles, but some additional data of my application. I could create a new cache for that, but obviously it would mean additional buffers (in heap and RMS), so I think it is good to store them together.
Unfortunately it doesn't always work - sometimes it produces "collisions" - my data, particularly images, are replaced with tiles from map.
I do not think it's a result of key collision - I generate my own keys for cache entries, and it's hardly possible MGMap engine uses the same key.
Since the cache is used asynchronously from map engine, and from the app, I wrapped CachingChain with sync code:
public class CommonCache extends CachingChain {
public synchronized void cache(String cacheKey, byte[] data, int cacheLevel) {
super.cache(cacheKey, data, cacheLevel);
}
public synchronized void deinitialize() {
super.deinitialize();
}
public synchronized void initialize() {
super.initialize();
}
public synchronized byte[] get(String cacheKey) {
return super.get(cacheKey);
}
public CommonCache(Cache[] cacheLevels) {
super(cacheLevels);
}
}
but still observe collisions like before syncing, per my observation happening when RMS cache limit is met.
Any suggestions how to fix that are appreciated. I would not like to use separate cache, but at this moment I do not see other way to go :(
Could that happen because of several deinitialize() calls, one from the app and other one from the map engine? Is deinitialize() a sync method, I mean if cache uses separate thread?
TIA,
Mike
Seems that I have resolved this, the solution was following:
The problem was that mgmap engine starts and stops cache (initialize() and deinitialize()) conflicting with my app. It should be done in one place.
So I made stubs for initialize() and deinitilize() in my cache class, to prevent the cache from being controlled from mgmap engine. And introduced new initialize and deinitialize methods delegating this functionality to my app.
Another solution can be creating a cache class which prevents double calls of initialize/deinitialize.
and I declared get() and cache() methods synchronous, of course
Additional question regarding cache: I place most data at CACHE_LEVEL_PERSISTENT, and some data, temporary on session level, to CACHE_LEVEL_MEMORY.
It is not quite clear from docs if such usage of the cache is OK, please confirm. May be it's better to place all data to CACHE_LEVEL_PERSISTENT to avoid collisions between cache layers?
Thanks,
Mike