Skip to content
This repository was archived by the owner on Aug 18, 2018. It is now read-only.

Commit b37f4df

Browse files
committed
cachehash added to params (for different attributes for a same resource)
1 parent 4d08d37 commit b37f4df

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-angular-jsonapi",
3-
"version": "0.6.19",
3+
"version": "0.6.20",
44
"description": "JSONAPI library developed for AngularJS in Typescript",
55
"repository": {
66
"type": "git",

src/library/interfaces/params-collection.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ interface IParamsCollection extends IParams {
77
smartfilter?: object;
88
page?: IPage;
99
storage_ttl?: number;
10+
cachehash?: string; // solution for when we have different resources with a same id
1011
}

src/library/service.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ export class Service extends ParentResourceService implements IService {
146146
angular.extend(params.remotefilter, params.smartfilter);
147147
}
148148

149+
params.cachehash = params.cachehash || '';
150+
149151
// http request
150152
let path = new PathBuilder();
151153
let paramsurl = new UrlParamsBuilder();
@@ -237,6 +239,14 @@ export class Service extends ParentResourceService implements IService {
237239
tempororay_collection.$source = 'server';
238240
tempororay_collection.$is_loading = false;
239241

242+
// this create a new ID for every resource (for caching proposes)
243+
// for example, two URL return same objects but with different attributes
244+
if (params.cachehash) {
245+
angular.forEach(success.data.data, resource => {
246+
resource.id = resource.id + params.cachehash;
247+
});
248+
}
249+
240250
Converter.build(success.data, tempororay_collection);
241251

242252
this.getService().cachememory.setCollection(path.getForCache(), tempororay_collection);

src/library/services/cachestore.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ export class CacheStore implements ICacheStore {
2424
);
2525
}
2626

27-
public getCollectionFromStorePromise(url:string, collection: ICollection): ng.IPromise<object> {
27+
public getCollectionFromStorePromise(url: string, collection: ICollection): ng.IPromise<object> {
2828
var deferred = Core.injectedServices.$q.defer();
2929
this.getCollectionFromStore(url, collection, deferred);
3030
return deferred.promise;
3131
}
3232

33-
private getCollectionFromStore(url:string, collection: ICollection, job_deferred: ng.IDeferred<ICollection> = null): void {
33+
private getCollectionFromStore(url: string, collection: ICollection, job_deferred: ng.IDeferred<ICollection> = null): void {
3434
let promise = Core.injectedServices.JsonapiStoreService.getObjet('collection.' + url);
3535
promise.then(success => {
3636
try {
@@ -54,6 +54,7 @@ export class CacheStore implements ICacheStore {
5454
}
5555
if (all_ok) {
5656
collection.$source = 'store'; // collection from storeservice, resources from memory
57+
collection.$cache_last_update = success._lastupdate_time;
5758
job_deferred.resolve(collection);
5859
return ;
5960
}

0 commit comments

Comments
 (0)