Small-Peer-Based Evictions
In most cases, choosing to use the Big Peer for TTL-based eviction management is ideal; however, in select scenarios where concerns like data availability, integrity, privacy, and security require local management, opting for the Small Peer local management approach may be the better choice.
Before invoking the Evict method to purge documents older than the TTL, cancel any active subscriptions that may be impacted by the eviction. (Canceling Affected Subscriptions)
By stopping any subscriptions affected by the evict update, you ensure that Ditto does not attempt to purge documents actively syncing across the mesh.
For more information about subscriptions, see Platform Manual > Data Sync.
Once you ensure that any ongoing subscriptions affected by the eviction update are canceled, run the eviction process. (See Invoking TTL-Based Eviction)
Once the eviction process is complete, set up a new subscription with your updated time‑based eviction criteria (Creating New Subscriptions)
Canceling Affected Subscriptions
To cancel a subscription:
To maintain data integrity, you must cancel any active subscription that the eviction update may impact *before *executing your eviction process.
Otherwise, an undesirable loop may result in which Ditto continuously evicts documents from the local Ditto store and then automatically re‑syncs them, leading to increased memory usage.
Invoking Eviction Updates
Using a top-level args
variable, declare your TTL.
Using the Find method, define your time‑based eviction criteria.
Using the Evict method, execute the eviction process on documents matching your criteria.
Notice that the query used for eviction is the opposite of the query used for subscription, enclosed as parameters in the Find method; that is, they do not select the same documents.
By using opposite queries, you prevent potential conflict by ensuring that the queries you use for eviction and subscription are distinct and do not overlap.
Creating New Subscriptions
To update a subscription with your updated time‑based eviction criteria, do the following:
You must declare your subscription object from the top-most scope of your app to ensure access throughout the life cycle of your app.
Otherwise, you cannot modify or cancel your subscription from any part of your code, resulting in difficulty and potential errors when managing the subscription’s lifecycle.
Specify the name of the collection to watch; for example, the "flights"
collection.
Using the Find method, define the query that retrieves documents where the "createdAt"
field is greater than the ttl
.
Using the Subscribe method, initiate your subscription.
Was this page helpful?