Read Only Cache initialization from DB

classic Classic list List threaded Threaded
5 messages Options
diopek diopek
Reply | Threaded
Open this post in threaded view
|

Read Only Cache initialization from DB

This post has NOT been accepted by the mailing list yet.
What is the best approach to implement READ-ONLY cache.

Setting cacheCfg.setWriteThrough(false); would disable write operations even underlying CacheStore has  has write and delete methods implemented.
Or, I should also add OperationNotSupported kind of exception to write/delete operations to eliminate inadvertent updates in underlying persistence store.
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: Read Only Cache initialization from DB

diopek wrote
What is the best approach to implement READ-ONLY cache.

Setting cacheCfg.setWriteThrough(false); would disable write operations even underlying CacheStore has  has write and delete methods implemented.
Or, I should also add OperationNotSupported kind of exception to write/delete operations to eliminate inadvertent updates in underlying persistence store.
Hi,

Can you please provide more details on your use case? What do you mean by read-only cache? How are you going to populate the cache and what read operations will you perform?

Note that setting cacheCfg.setWriteThrough(false) will only prevent you from writing to persistence store, but cache will still be updated if put() or remove() method is called.

-Val
diopek diopek
Reply | Threaded
Open this post in threaded view
|

Re: Read Only Cache initialization from DB

This post has NOT been accepted by the mailing list yet.
In my use case, basically certain caches will be populated from DB tables on demand for read-only purposes. Updates are being done at certain dates directly in database tables. I believe one way to do that is to use standard cache api (put) to populate the cache without backing up with CacheStore.
I also saw this CacheLoadOnlyStoreAdapter<K,V,I> class, but I am not sure is that good fit to initialize cache from DB tables and eliminates updates to persistent store.
Regarding your statement, is there a way (configuration) to define immutable caches?
>>Note that setting cacheCfg.setWriteThrough(false) will only prevent you from writing to persistence store, but cache will still be updated if put() or remove() method is called.
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: Read Only Cache initialization from DB

diopek wrote
In my use case, basically certain caches will be populated from DB tables on demand for read-only purposes. Updates are being done at certain dates directly in database tables. I believe one way to do that is to use standard cache api (put) to populate the cache without backing up with CacheStore.
I also saw this CacheLoadOnlyStoreAdapter<K,V,I> class, but I am not sure is that good fit to initialize cache from DB tables and eliminates updates to persistent store.
Regarding your statement, is there a way (configuration) to define immutable caches?
>>Note that setting cacheCfg.setWriteThrough(false) will only prevent you from writing to persistence store, but cache will still be updated if put() or remove() method is called.
OK, it looks like you want to read-through from the database and invalidate the data in cache once it's updated in the database. Is this right?

To implement read-through you should configure your store with load() method implemented and set CacheConfiguration.setReadThrough(true), like described here: https://apacheignite.readme.io/docs/persistent-store

For invalidation you have two options:
1. Have a DB trigger that will somehow (e.g., via REST request) remove required mappings from the cache. You can use IgniteCache.clear(key) method for this.
2. Use expiration. Define it via CacheConfiguration.setExpiryPolicyFactory() configuration property and entries in the cache will be invalidated based on provided policy.

Will this work for you?

-Val
kcheng.mvp kcheng.mvp
Reply | Threaded
Open this post in threaded view
|

Re: Read Only Cache initialization from DB

In reply to this post by vkulichenko
Yes, that's what I want. but I am blocked by the issue

https://issues.apache.org/jira/browse/IGNITE-1246