What is the fastest, most lightweight option to see if an object has changed?

1
We’ve got a database with lots of data and created a new product that only uses a subset of that data. In order to improve performance, we duplicated that subset of data in it’s own module, reducing database tables and columns. Read this like some kind of cache storage. Now that separate API is very fast, but the question is: Is it accurate and up to date? The data in the initial database is updated now and then, but the aforementioned API should provide up to date information as well. Upon each request it should check for a few objects whether data has changed or not. Aside of how to store ChangeDates, I was wondering regarding the best way to compare two objects for differences, before even retrieving them both. Alright, let’s name an object from the actual database ‘A’ and the cached version ‘B’. Now I request, through an API, ‘B’ and have to check if it’s primary object has changed. I could retrieve A, compare ChangeDates or an Hashed attribute, and either update B or return B, depending on the outcome. But I currently have A retrieved, which costs (minimal) processing power. Could I check for changes without retrieving and solely retrieve when there are changes? A solution would be to retrieve the primary object as a list, including a matching hash (B.UniqueHashString = A.UniqueHashString) and immediately a CountList afterwards. If the hash of primary and cache match, the list returns 1, the query only returns a count (returning ‘1’) and you know B=A. If not, A has changed and B should be updated. But is that the fastest way? – Hashes on the primary object changes upon each commit, assuming something has changed. The cache will copy the hash to assume it has been updated as well.
asked
2 answers
1

I would go with André's suggestion an update B when changing A. In your current setup, retrieving the original A objects, checking everytime, and possibly update B makes me wonder why you even bother with B and not just serve object A to user.

Example:

Object A gets changed one a day. One event to update object B. Object B gets requested 100 times a day, is always up to date so gets returned immediately.

in comparison to

Object B gets requested. object A gets retrieved. object comparison, possible update and return object B. 100 times a day. 

answered
0

Hi Sander,

 

Any progress on this matter?

 

regards,

Andre

answered