Skip to content

Commit

Permalink
refactor: finalize cachemanager api
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Mar 10, 2020
1 parent 06c1cd6 commit 21ebb45
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/CacheManager/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* @module edge
*/

/*
* edge
*
Expand All @@ -11,15 +7,23 @@
* file that was distributed with this source code.
*/

import { LoaderTemplate } from '../Contracts'
import { LoaderTemplate, CacheManagerContract } from '../Contracts'

/**
* In memory cache manager to cache pre-compiled templates
* In memory cache manager to cache pre-compiled templates.
*/
export class CacheManager {
private _cacheStore: Map<string, LoaderTemplate> = new Map()
export class CacheManager implements CacheManagerContract {
private cacheStore: Map<string, LoaderTemplate> = new Map()

constructor (private _enabled: boolean) {
constructor (private enabled: boolean) {
}

/**
* Returns a boolean to tell if a template has already been cached
* or not.
*/
public has (absPath: string): boolean {
return this.cacheStore.has(absPath)
}

/**
Expand All @@ -28,22 +32,22 @@ export class CacheManager {
* return undefined.
*/
public get (absPath: string): undefined | LoaderTemplate {
if (!this._enabled) {
if (!this.enabled) {
return
}

return this._cacheStore.get(absPath)
return this.cacheStore.get(absPath)
}

/**
* Set's the template path and the payload to the cache. If
* cache is disabled, then this function returns in noop.
*/
public set (absPath: string, payload: LoaderTemplate) {
if (!this._enabled) {
if (!this.enabled) {
return
}

this._cacheStore.set(absPath, payload)
this.cacheStore.set(absPath, payload)
}
}

0 comments on commit 21ebb45

Please sign in to comment.