Skip to content
Snippets Groups Projects
Verified Commit bb5286d3 authored by Hadrien RENAUD's avatar Hadrien RENAUD
Browse files

Create Cache

parent 83d18212
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ import { User } from "../object_resolvers/users";
import knex from "../../../db/knex_router"
import { GroupCollection, GroupSet, Tools } from "../../utils/tools";
import { createSubgroupArgs, editGroupArgs } from "../typeDefs/queries";
import {Cache} from "../../utils/cache";
export class GroupModel {
......@@ -28,6 +29,8 @@ export class GroupModel {
protected contextUser: string;
protected cache: Cache<Group, string>;
/**
* @memberof GraphQL.GroupModel#
* @function getGroup
......
/**
* @file Fonctions et classes de cache
* @author hadi
* @namespace cache
*/
export class Cache<A, K> {
/**
* @memberof cache
* @class Cache
* @summary Permet le caching d'une classe A référencée par des keys K
*/
instances = new Map<K, A>();
aConstructor: new (k: K) => A;
constructor(aConstructor: new (k: K) => A) {
this.aConstructor = aConstructor;
}
get(k: K){
if (this.instances.has(k))
return this.instances.get(k);
else {
const a = new this.aConstructor(k);
this.instances.set(k, a);
return a;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment