Reputation: 3924
Current Scenario :-
I have a C# code which gets data from MySql server (data from Strored procedures) and stores the data in JSON format in Redis. This updates the cache (redis) for about every half an hour, irrespective of whether the data in mysql remains same / different (since i don't have clue about data change).
Requirement :-
Need to build the same system, instead of updating cache in predefined intervals even when the data is same i need to modify the cache only when the data is changed.
Couchbase :-
I heard of couchbase views. I am very new to that. I can change my data from mysql to JSON Documents in couchbase. My Question is, will this couchbase views is suitable for that ?
My Idea is
1. Data from MySql => JSON in couchbase bucket
2. StoredProcedure logic => couchbase views
When the data from couchbase bucket changes, then this view should run again otherwise it should fetch from cache without running the view again. Is this possible in views ?
If not please tell any other solution for this.
Thanks in advance.
Upvotes: 1
Views: 3053
Reputation: 2538
In couchbase views update can be triggered manually or automatically.
For auto triggering view update you can do it in two ways: periodical update and update based on number of changed documents. You can view current settings via GET query to: http://Administrator:Password@nodename:8091/settings/viewUpdateDaemon
and update them via POST request.
See more details see the Couchbase Server manual docs.
The other way is to trigger couchbase view update manually. This can be done through quering view with stale=false
param or stale=update_after
.
If you pass stale=false
view index will be updated and you will get actual data. This query can take a lot of time, if you have a lot of documents.
If you pass stale=update_after
, the view will return current data (probably cached) and after returning data it will start index update process. This query will be fast, but you can get cached data, but if you just want to trigger update process this approach is good enough.
Here is a link to docs for more info.
So you should decide what approach suits you more, if you need updated data immediately populated in cache, manual triggering will be better. If you don't need that, you can probably use automatic approach and set update trigger to run reindex after certain amount of record updates.
Upvotes: 2