feat(dag-protobuf): cache dag pb directory structure and block indexes #147
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
The requests to fetch a DAG Protobuf directory structure using a CID execute the following steps:
bafy...cid
- which represents the folder containing the target file, so that we can determine the verifiable cid for the file (let's call thatbafy...file
)bafy...file
to get the root block of the file, which in UnixFS contains NO raw data, but rather is a list of sub-blocks that contain the file (let's call thosebafy...bytes1
andbafy...bytes2
)This PR enables the caching strategy for steps 2 to 4 where instead of fetching the directory structure from the locator and navigating the DAG for every request, it caches the DAGs if they have a Protobuf structure and content size <= 2MB.
Changes
withContentClaimsDagula
middleware to cache DAG PB content requestsDAGPB_CONTENT_CACHE
FF_DAGPB_CONTENT_CACHE_TTL_SECONDS
: The number that represents when to expire the key-value pair in seconds from now. The minimum value is 60 seconds. Any value less than 60MB will not be used. We will use 5 minutes TTL by default.FF_DAGPB_CONTENT_CACHE_MAX_SIZE_MB
: The maximum size of the key-value pair in MB. The minimum value is 1 MB. Any value less than 1MB will not be used. We will use 2MB max file size by default.FF_DAGPB_CONTENT_CACHE_ENABLED
: The flag that enables the DAGPB content cache. The cache is disabled in prod by default.Samples
2MB file - no cache
2MB file - cached
KV Limits
resolves storacha/project-tracking#301