-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Ajout) Le caching version 0.5 est là. Principalement pour du renderi…
…ng. Si une méthode est appeler plus d'une fois pendant le render, la cache renvoit le query cached.
- Loading branch information
Showing
5 changed files
with
88 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Store request and data here to avoid multiple fetch. | ||
*/ | ||
class Caching { | ||
|
||
cacheObjects; | ||
|
||
constructor() { | ||
this.cacheObjects = {}; | ||
console.log("Caching initiated"); | ||
} | ||
|
||
/** | ||
* register the key into a property and set the key's value into the cacheObject | ||
* @param key | ||
* @param value | ||
*/ | ||
set(key, value) { | ||
this.register(key, value); | ||
this.cacheObjects[key] = value; | ||
} | ||
|
||
/** | ||
* Basic get from string | ||
* @param key {string} | ||
* @return {*|null} | ||
*/ | ||
get(key) { | ||
if (this.has(key)) { | ||
return this.cacheObjects[key]; | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* boolean check if the key have allready a value. | ||
* @param key {string} | ||
* @return {boolean} | ||
*/ | ||
has(key) { | ||
console.log("has", key, (key in this.cacheObjects), "have a value", typeof this.cacheObjects[key]); | ||
return (key in this.cacheObjects); | ||
} | ||
|
||
/** | ||
* Register the key as a property of the caching object assigning to the that class get / set. | ||
* @param key {string} the string value of the cache elements. | ||
* @param value {*} what need to be cached | ||
* @return {*} | ||
*/ | ||
register (key, value) { | ||
if (!this[key]) { | ||
Object.defineProperty(this, key, { | ||
get() { | ||
return this.get(key); | ||
}, | ||
set(newvalue) { | ||
this.set(key, newvalue); | ||
}, | ||
enumerable: true, | ||
configurable: true, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
export default Caching; |
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