Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FE-256-fix-force-ttl-0 auto-commit #306

Open
wants to merge 3 commits into
base: v2.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Fixed

- when ttl 0 was set, a request to the server was not made again, it brought it from memory, it was corrected in the isLive function of common.

## [2.2.1] - 2020-10-17

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DocumentCollection } from './document-collection';
import { Resource } from './resource';

export function isLive(cacheable: ICacheable, ttl?: number): boolean {
let ttl_in_seconds = ttl && typeof ttl === 'number' ? ttl : cacheable.ttl || 0;
let ttl_in_seconds = typeof ttl === 'number' ? ttl : cacheable.ttl || 0;

return Date.now() < cacheable.cache_last_update + ttl_in_seconds * 1000;
}
Expand Down
26 changes: 26 additions & 0 deletions src/service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,32 @@ for (let store_cache_method of store_cache_methods) {
expect(http_request_spy).toHaveBeenCalledTimes(0);
});

it(`with cached on memory (live) collection emits source ^memory-server| when force ttl = 0 on call`, async () => {
// caching collection
test_response_subject.next(new HttpResponse({ body: TestFactory.getCollectionDocumentData(Book) }));
booksService.collections_ttl = 5; // live
await booksService.all({ store_cache_method: store_cache_method }).toPromise();

let http_request_spy = spyOn(HttpClient.prototype, 'request').and.callThrough();
let expected = [
// expected emits
{ builded: true, loaded: false, source: 'memory' },
{ builded: true, loaded: true, source: 'server' }
];

let emits = await booksService
.all({ ttl: 0, store_cache_method: store_cache_method })
.pipe(
map(emit => {
return { builded: emit.builded, loaded: emit.loaded, source: emit.source };
}),
toArray()
)
.toPromise();
expect(emits).toMatchObject(expected);
expect(http_request_spy).toHaveBeenCalledTimes(1);
});

it(`with cached on memory (dead) collection emits source ^memory-server|`, async () => {
// caching collection
test_response_subject.next(new HttpResponse({ body: TestFactory.getCollectionDocumentData(Book) }));
Expand Down