Skip to content

Commit 6e5c116

Browse files
committed
Add documentation on context resolver
1 parent 32264c2 commit 6e5c116

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ attempt to use a locally cached version of contexts (see
216216
[§ Cache JSON-LD Contexts](https://w3c.github.io/json-ld-bp/#cache-json-ld-contexts)).
217217
Refresh the bundled copies with `make download-bundled-contexts`.
218218

219-
### Customizing the ContextLoader
219+
### Customizing the ContextResolver
220220

221221
You can customize the way contexts are loaded and cached by passing an instance
222222
of `ContextResolver`. The following example implements a loader with a prefilled

docs/reference/context-resolver.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# :material-cached: `ContextResolver`
2+
3+
`ContextResolver` resolves remote `@context` documents and caches the resolved
4+
contexts used by JSON-LD operations.
5+
6+
::: pyld.ContextResolver
7+
options:
8+
show_root_heading: false
9+
show_bases: false
10+
heading_level: 3
11+
12+
Pass a custom `ContextResolver` with the `contextResolver` option when you need
13+
to provide your own resolved-context cache or adjust the remote-context recursion
14+
limit. The resolver still uses a `DocumentLoader` to fetch remote context
15+
documents, so pass the same loader with `documentLoader`.
16+
17+
{{ example('context_resolver.py', output_syntax='json') }}
18+
19+
The `shared_cache` object must behave like a mutable mapping. PyLD uses
20+
`cachetools.LRUCache` by default, but applications can provide another mapping
21+
when they need a different eviction policy.
22+
23+
Use `max_context_urls` to change how many remote contexts may be fetched while
24+
resolving nested or imported contexts.

docs/reference/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ hide: [toc]
6767

6868
Load remote JSON-LD documents and contexts with the built-in loader classes.
6969

70+
- [:material-cached:{ .lg .middle } `ContextResolver`](context-resolver.md)
71+
72+
---
73+
74+
Resolve and cache remote `@context` documents during JSON-LD processing.
75+
7076
- :material-hard-hat:{ .lg .middle } __In construction__
7177

7278
---

0 commit comments

Comments
 (0)