Skip to content

Commit

Permalink
chore: a bit of an explanation of how cachedValues work
Browse files Browse the repository at this point in the history
  • Loading branch information
kmruiz committed Feb 4, 2025
1 parent 971148f commit cf4e466
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ class DataGripBasedReadModelProvider(

@VisibleForTesting
internal var wasCached: Boolean = false

/**
* LocalDataSource implements ModificationTracker, which is a mechanism by which a consumer
* of the data source can detect if the metadata of the LocalDataSource has changed. This
* modification is similar to a versioning system, it contains a Long value that contains
* the current version, and on each change it just increases by 1.
*
* We are using the `modificationCount` as a modification stamp: if the modification count
* did not change *and we already have a result from that slice* we can just return the cached
* result. Otherwise, we call the slice and store the current modificationCount along with the
* result of the query.
*/
private val cachedValues: ConcurrentMap<String, Pair<Long, *>> = ConcurrentHashMap()

override fun <T : Any> slice(
Expand Down

0 comments on commit cf4e466

Please sign in to comment.