-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #955 from visualize-admin/feat/lru-cache
- Loading branch information
Showing
9 changed files
with
187 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { | ||
SparqlQuery, | ||
SparqlQueryExecutable, | ||
} from "@tpluscode/sparql-builder/lib"; | ||
import StreamClient from "sparql-http-client"; | ||
import { ParsingClient } from "sparql-http-client/ParsingClient"; | ||
import { LRUCache, LRUCacheOptions } from "typescript-lru-cache"; | ||
|
||
type SparqlClient = StreamClient | ParsingClient; | ||
|
||
export const makeExecuteWithCache = <T>({ | ||
parse, | ||
cacheOptions, | ||
}: { | ||
parse: (v: any) => T; | ||
cacheOptions: LRUCacheOptions<string, T>; | ||
}) => { | ||
const cache = new LRUCache({ | ||
entryExpirationTimeInMS: 60 * 10_000, | ||
...cacheOptions, | ||
}); | ||
return async ( | ||
sparqlClient: SparqlClient, | ||
query: SparqlQuery & SparqlQueryExecutable | ||
) => { | ||
const key = `${sparqlClient.query.endpoint.endpointUrl} - ${query.build()}`; | ||
const cached = cache.get(key); | ||
if (cached) { | ||
return cached; | ||
} else { | ||
const result = await query.execute(sparqlClient.query, { | ||
operation: "postUrlencoded", | ||
}); | ||
const parsed = parse(result) as T; | ||
cache.set(key, parsed); | ||
return parsed; | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
fb87d10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
visualization-tool – ./
visualization-tool-alpha.vercel.app
visualization-tool-git-main-ixt1.vercel.app
visualization-tool-ixt1.vercel.app