Expand description
Cache module.
This module exists to support two main design goals:
- API calls to AnkiConnect are (very) expensive, so we want to keep them to a minimum.
- At the same time, we want the calls we do make to succeed.
To aid with the 1st goal, we make stipulate that the contents of Typst files syncing to Anki take precedence over the contents of Anki’s database. So, for example, if a user modifies a note in Anki that was generated by Ankify, those changes may be overwritten the next time Ankify syncs that note. This principle implies that we can keep track of the contents of Ankify-generated notes in the Anki database by keeping track of the last content that we pushed to them. We do this as follows:
- We track the contents of each field of each note we pushed.
- For Png and Svg contents, this tracking is done by hashing the corresponding media file and storing the hash in the cache.
- For Plain contents, we hash the text directly.
For each note, we also track tags, deck, model, and the ID that Anki
assigned to the note. This will help us address the 2nd design goal, as
we’ll see in the sync module.
This module is meant to specifically serve the sync module, which is
responsible for synchronizing notes between Typst and Anki. The sync
module may ask the cache module to
- read the cache, so that the
syncmodule can determine which AnkiConnect requests to make, and to - update the cache, after the
syncmodule has received a response from AnkiConnect indicating that a request was successful. To update the cache, thecachemodule will receive notes in the form ofNotestructs, as defined in themetadatamodule.
Structs§
- Cache
- The main cache structure that manages cached note data.
- Cache
Entry - A cache entry representing the last known state of a note in Anki.
- Label
- Label of a note, as parsed from a Typst file’s metadata.
- Sha256
- A SHA-256 hash represented as a hexadecimal string.