This repository was archived by the owner on Aug 18, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +15
-3
lines changed
Expand file tree Collapse file tree 4 files changed +15
-3
lines changed Original file line number Diff line number Diff line change 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" ,
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments