Skip to content

Commit b8ee984

Browse files
committed
Expose clearCache path.
Closes LDflex/LDflex-Comunica#4. Closes #6.
1 parent 754cdd5 commit b8ee984

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import CreateActivityHandler from './CreateActivityHandler';
55
import SourcePathHandler from './SourcePathHandler';
66
import UserPathHandler from './UserPathHandler';
77
import SubjectPathResolver from './SubjectPathResolver';
8+
import ComunicaUpdateEngine from './ComunicaUpdateEngine';
89

910
const { as } = context['@context'];
1011

@@ -34,14 +35,20 @@ export default rootPath = new PathFactory({
3435
// Handlers of specific named properties
3536
handlers: {
3637
...defaultHandlers,
38+
3739
// The `from` property takes a source URI as input
3840
from: new SourcePathHandler(subjectPathFactory),
3941
// The `user` property starts a path with the current user as subject
4042
user: new UserPathHandler(subjectPathFactory),
43+
44+
// Clears the cache for the given document (or everything, if undefined)
45+
clearCache: ({ settings }) => doc => settings.queryEngine.clearCache(doc),
4146
},
4247
// Handlers of all remaining properties
4348
resolvers: [
4449
// `data[url]` starts a path with the property as subject
4550
new SubjectPathResolver(subjectPathFactory),
4651
],
52+
// Global query engine (currently only used for clearing the cache)
53+
queryEngine: new ComunicaUpdateEngine(),
4754
}).create();

test/index-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ describe('The @solid/ldflex module', () => {
6767
expect(data.user.root.root.user.root).toBe(data);
6868
});
6969
});
70+
71+
describe('the clearCache path', () => {
72+
it('returns a function to clear the cache', () => {
73+
const document = {};
74+
data.clearCache(document);
75+
expect(ComunicaUpdateEngine.prototype.clearCache).toHaveBeenCalledTimes(1);
76+
expect(ComunicaUpdateEngine.prototype.clearCache).toHaveBeenCalledWith(document);
77+
});
78+
});
7079
});
7180

7281
const urlQuery = `SELECT ?firstName WHERE {

0 commit comments

Comments
 (0)