Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pheyvaer committed Mar 9, 2022
1 parent 6bb52b4 commit b575f5b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/any-to-rdf-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export class AnyToRdfConverter extends BaseTypedRepresentationConverter {
);
}

/**
* Get RDF from the cache.
* @param data - The data to use to determine the hash for the caching.
*/
_getRDFFromCache(data: string) {
if (this.cache) {
const hash: string = crypto.createHash('md5').update(data).digest("hex");
Expand All @@ -125,13 +129,22 @@ export class AnyToRdfConverter extends BaseTypedRepresentationConverter {
return null;
}

/**
* Store RDF in the cache.
* @param data - The data that is used to determine to hash for caching.
* @param rdf - The RDF that is stored.
*/
_setRDFinCache(data: string, rdf: string) {
if (this.cache) {
const hash: string = crypto.createHash('md5').update(data).digest("hex");
this.cache[hash] = {rdf, lastUsed: new Date()};
}
}

/**
* This method removes RDF from the cache that hasn't been used in a while.
* This is based on this.cacheRetention.
*/
_cleanUpCache() {
const now = (new Date()).getTime();
// @ts-ignore
Expand All @@ -152,6 +165,9 @@ export class AnyToRdfConverter extends BaseTypedRepresentationConverter {
});
}

/**
* This method stops the automatic clean up of the cache.
*/
stopCacheCleanUps() {
if (this.intervalID) {
clearInterval(this.intervalID);
Expand Down
1 change: 0 additions & 1 deletion test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ chai.use(chaiAsPromised);
* Converts a JSON input to RDF and converts the stream to string.
* @param input - JSON to convert to RDF.
* @param converter - AnyToRdfConverter you want to reuse. If not provided a new one is created.
* @param cache - Use cache (optional, default is false).
* @returns Converted input in string format.
*/
const convertJsonToRDF = async (input: any, converter?: AnyToRdfConverter): Promise<any> => {
Expand Down

0 comments on commit b575f5b

Please sign in to comment.