Bookmark Maintenance API
Bookmark keys preserve sort-field order and BSON/RegExp types, including document field order inside let. Prewarm, read, exact list and exact clear share effective ObjectId conversion, limit caps, cursor strategy and result options, including let and collation. Defined top-level options override nested options; equivalent effective options share an identity. The v4 keys start cold; old entries expire by their TTL or can be removed with collection-wide bookmark clearing.
Overview
monSQLize provides three bookmark maintenance APIs for managing findPage() bookmark caches. These APIs are intended for operational diagnostics and pagination performance tuning.
Bookmark keys use the same source/authentication/pool cache scope and cursor strategy as findPage(). Pass matching cursorTypes and cursorValueNormalizerVersion in keyDims when warming, listing, clearing and querying. Instance defaults apply; a per-call normalizer override needs its own non-empty stable version. prewarmBookmarks() throws INVALID_ARGUMENT for an unversioned custom normalizer; queries can still run but do not reuse bookmarks automatically. Upgrade behavior is described in Cache Invalidation.
The key strings below are conceptual examples. Use the returned keys/patterns or bookmark APIs; do not construct keys from getNamespace().
Core Features
- ✅ Smart Hash Matching: Automatically applies
ensureStableSortnormalization, ensuring the same cache key as findPage is used - ✅ Precise Control: Supports managing bookmarks for specific queries by
keyDims - ✅ Global Cleanup: Omit
keyDimsto operate on all bookmarks in the collection - ✅ Out-of-range Detection:
prewarmBookmarksautomatically detects pages beyond the available data - ✅ Cache Availability Check: All APIs throw a
CACHE_UNAVAILABLEerror when cache is not available
Usage scenarios
- Startup warm-up - Warm hot pages to reduce first-query latency
- Operations monitoring - View cached page distribution
- Refresh bookmarks after data changes - Keep page navigation aligned with current data
- Memory management - Clean bookmarks to release resources on demand
API Description
1. prewarmBookmarks(keyDims, pages)
Warm up bookmark cache entries for the specified pages.
Method signature
Parameters
keyDims object:
Return value
Usage examples
Error handling
2. listBookmarks(keyDims?)
List cached bookmarks (supports filtering by query or viewing all).
Method signature (2. listBookmarks(keyDims?))
Parameters (2. listBookmarks(keyDims?))
Return value (2. listBookmarks(keyDims?))
Filter by query:
View All:
Usage example (2. listBookmarks(keyDims?))
Operation and maintenance monitoring scenario
3. clearBookmarks(keyDims?)
Clears the specified query or all bookmark caches.
Method signature (3. clearBookmarks(keyDims?))
Parameters (3. clearBookmarks(keyDims?))
Return value (3. clearBookmarks(keyDims?))
Usage example (3. clearBookmarks(keyDims?))
Data update scenario
Complete workflow example
Scenario 1: System startup warm-up
Scenario 2: Clean up expired bookmarks regularly
Scenario 3: Refresh bookmarks after data updates
Scenario 4: Monitoring and Statistics
Best Practices
1. Warm-up strategy
2. Cleanup timing
3. Monitoring and Alerting
Notes
- Cache key matching:
sortinkeyDimsautomatically appliesensureStableSortnormalization so the same cache key is used asfindPage() - Cache Availability: All APIs throw
CACHE_UNAVAILABLEerrors when the cache is unavailable. Make sure the cache is configured before use. - Memory Management: Warming up too many pages will occupy a lot of memory. It is recommended to only warm up the first few pages that are commonly used.
- Failure page:
prewarmBookmarksautomatically detects pages out of range. Failure pages will not affect the warm-up of successful pages. - Read path usage: matching bookmarks are consumed by
findPage()page navigation to resume from the nearest warmed page. - Global Cleanup: when
clearBookmarks()is called without parameters, all bookmarks in the collection are cleared. Use it carefully.
Error handling (Part 2)
References
- findPage method document
- Cache Policy Document
- bookmarks sample code
- Performance optimization guide