Skip to content
This repository was archived by the owner on Apr 30, 2019. It is now read-only.

Commit c8a3d97

Browse files
committed
Merge branch 'ericvw-remove_getcachekey'
2 parents a8bf217 + 2f10e35 commit c8a3d97

File tree

4 files changed

+17
-26
lines changed

4 files changed

+17
-26
lines changed

src/git/GithubRepo.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,13 @@ class GithubRepo {
3333
this.config = config;
3434
this.urls = new GithubURLs(this);
3535

36-
this.storeDir = path.join(storeDir.replace(/[\\\/]+$/, ''), this.getCacheKey());
36+
var cacheKey = this.config.repoOwner + '-' + this.config.repoProject;
37+
this.storeDir = path.join(storeDir.replace(/[\\\/]+$/, ''), cacheKey);
3738

3839
this.api = new GithubAPI(this.urls, opts.getChild('git/api'), opts, this.storeDir);
3940
this.raw = new GithubRaw(this.urls, opts.getChild('git/raw'), opts, this.storeDir);
4041
}
4142

42-
getCacheKey(): string {
43-
return this.config.repoOwner + '-' + this.config.repoProject;
44-
}
45-
4643
toString(): string {
4744
return this.config.repoOwner + '/' + this.config.repoProject;
4845
}

src/git/loader/GithubAPI.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,18 @@ import GithubRateInfo = require('../model/GithubRateInfo');
2525
class GithubAPI extends GithubLoader {
2626

2727
// github's version
28-
private apiVersion: string = '3.0.0';
28+
private static API_VERSION: string = '3.0.0';
29+
private static FORMAT_VERSION: string = '1.0';
30+
private static CACHE_KEY: string = 'git-api-v' + GithubAPI.API_VERSION + '-fmt' + GithubAPI.FORMAT_VERSION;
31+
32+
static NAME: string = 'GithubAPI';
2933

3034
constructor(urls: GithubURLs, options: JSONPointer, shared: JSONPointer, storeDir: string) {
31-
super(urls, options, shared, storeDir, 'GithubAPI');
35+
super(urls, options, shared, storeDir, GithubAPI.NAME);
3236

33-
this.formatVersion = '1.0';
37+
this.formatVersion = GithubAPI.FORMAT_VERSION;
3438

35-
this._initGithubLoader();
39+
this._initGithubLoader(GithubAPI.CACHE_KEY);
3640
}
3741

3842
getBranches(): Promise<any> {
@@ -122,10 +126,6 @@ class GithubAPI extends GithubLoader {
122126
});
123127
});
124128
}
125-
126-
getCacheKey(): string {
127-
return 'git-api-v' + this.apiVersion + '-fmt' + this.formatVersion;
128-
}
129129
}
130130

131131
export = GithubAPI;

src/git/loader/GithubLoader.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ class GithubLoader {
4545
this.label = label;
4646
}
4747

48-
_initGithubLoader(): void {
48+
_initGithubLoader(cacheKey: string): void {
4949
var cache = new CacheOpts();
5050
cache.allowClean = this.options.getBoolean('allowClean', cache.allowClean);
5151
cache.cleanInterval = this.options.getDurationSecs('cacheCleanInterval', cache.cleanInterval / 1000) * 1000;
5252
cache.splitDirLevel = this.options.getNumber('splitDirLevel', cache.splitDirLevel);
5353
cache.splitDirChunk = this.options.getNumber('splitDirChunk', cache.splitDirChunk);
5454
cache.jobTimeout = this.options.getDurationSecs('jobTimeout', cache.jobTimeout / 1000) * 1000;
55-
cache.storeDir = path.join(this.storeDir, this.getCacheKey());
55+
cache.storeDir = path.join(this.storeDir, cacheKey);
5656

5757
var opts: HTTPOpts = {
5858
cache: cache,
@@ -73,11 +73,6 @@ class GithubLoader {
7373
this.headers['user-agent'] = this.label + '-v' + this.formatVersion;
7474
}
7575

76-
getCacheKey(): string {
77-
// override
78-
return 'loader';
79-
}
80-
8176
copyHeadersTo(target: any, source?: any) {
8277
source = (source || this.headers);
8378
Object.keys(source).forEach((name) => {

src/git/loader/GithubRaw.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ import GithubRateInfo = require('../model/GithubRateInfo');
1919
GithubRaw: get files from raw.github.com and cache on disk
2020
*/
2121
class GithubRaw extends GithubLoader {
22+
private static API_VERSION: string = '3.0.0';
23+
private static FORMAT_VERSION: string = '1.0';
24+
private static CACHE_KEY = 'git-raw-fmt' + GithubRaw.FORMAT_VERSION;
2225

2326
constructor(urls: GithubURLs, options: JSONPointer, shared: JSONPointer, storeDir: string) {
2427
super(urls, options, shared, storeDir, 'GithubRaw');
2528

26-
this.formatVersion = '1.0';
29+
this.formatVersion = GithubRaw.FORMAT_VERSION;
2730

28-
this._initGithubLoader();
31+
this._initGithubLoader(GithubRaw.CACHE_KEY);
2932
}
3033

3134
getText(ref: string, filePath: string): Promise<string> {
@@ -68,10 +71,6 @@ class GithubRaw extends GithubLoader {
6871
return object.body;
6972
});
7073
}
71-
72-
getCacheKey(): string {
73-
return 'git-raw-fmt' + this.formatVersion;
74-
}
7574
}
7675

7776
export = GithubRaw;

0 commit comments

Comments
 (0)