Big-Peer-Based Evictions
As Ditto’s recommended approach, by opting to use the Big Peer to manage TTL-based evictions not only do you ensure that locally stored documents sync with the Big Peer before eviction, but you also streamline the eviction process by reducing the frequency of needing to perform subscription updates on Small Peers to align with the latest TTL queries.
To Implement TTL-based evictions using the Big Peer make a POST
request to the /api/v4/store/write
endpoint:
Using a top-level args
variable, declare your TTL.
Include the necessary authorization headers. For information on access credentials, see Onboarding.
In your request body, indicate which documents to target for eviction. (See Specifying Targets for Purge)
Configure your HTTP server to run the TTL-based eviction operation at regular intervals using HTTP API calls.
For example, set it to run daily, removing all documents older than 24 hours from the current day.
Make sure the Small Peer devices are evicting and subscribing to the right documents. (See Configuring Small Peers)
Specifying Targets for Purge
-
Pass the
update
command. -
Specify the target collection; for instance, the
“orders”
collection. -
Using a
query
, define time‑based eviction criteria to select documents where thecreatedAt
time is less than or equal to$TTL
. -
Ensure only eligible documents, those not previously evicted, are considered by setting
evictionFlag
in your query totrue
.
Configuring Small Peers
Once you’ve configured for TTL-based eviction management using the Big Peer, configure Small Peers to make sure their devices are evicting and subscribing to the right documents:
Using the Find method, evict all documents that have the evictionFlag
set to true
.
Using the EVICT method, execute the eviction process on the documents that match your time-based eviction criteria.
Once eviction is complete, using the Find method, subscribe to all documents that have the evictionFlag
set to false
.
Using the Subscribe method, execute the sync subscription on the documents that match your query criteria.
Make sure to remove the timestamp range from your subscription query.
This is because, by using the Big Peer for management, Small Peers no longer need to perform regular subscription updates to align their time-based eviction criteria in their queries.
Was this page helpful?