2 * Service for communicating with the server-side "anonymous" cache.
4 import {Injectable} from '@angular/core';
5 import {Observable} from 'rxjs/Observable';
6 import {StoreService} from '@eg/core/store.service';
7 import {NetService} from '@eg/core/net.service';
9 // All anon-cache data is stored in a single blob per user session.
10 // Value is generated on the server with the first call to set_value
11 // and stored locally as a LoginSession item (cookie).
14 export class AnonCacheService {
16 constructor(private store: StoreService, private net: NetService) {}
18 getItem(cacheKey: string, attr: string): Promise<any> {
19 return this.net.request(
21 'open-ils.actor.anon_cache.get_value', cacheKey, attr
25 // Apply 'value' to field 'attr' in the object cached at 'cacheKey'.
26 // If no cacheKey is provided, the server will generate one.
27 // Returns a promised resolved with the cache key.
28 setItem(cacheKey: string, attr: string, value: any): Promise<string> {
29 return this.net.request(
31 'open-ils.actor.anon_cache.set_value',
33 ).toPromise().then(cacheKey => {
37 return Promise.reject(
38 `Could not apply a value for attr=${attr} cacheKey=${cacheKey}`);
43 removeItem(cacheKey: string, attr: string): Promise<string> {
44 return this.net.request(
46 'open-ils.actor.anon_cache.set_value',
51 clear(cacheKey: string): Promise<string> {
52 return this.net.request(
54 'open-ils.actor.anon_cache.delete_session', cacheKey