27
loading...
This website collects cookies to deliver better user experience
CachedHttpService
. This TTL cache was developed out of a need to keep the PWA snappy and keep data consumption low. If you think about the usage patterns of someone using Spotify, people may sometimes spend lots of time browsing different artists, albums, tracks, etc. which could result in a lot of extra round trips between the client and Spotify servers. This service was developed to provide a centralized mechanism to cache all HTTP requests. This allows for any other service to leverage the same caching strategy, resulting in faster development times.ArtistService
, TrackService
, etc. all follow a repeatable and consistent pattern which reduces the chances for any silly bugs.@Injectable()
export class MyService {
// Inject the service here
constructor(private http: CachedHttpService) {}
getSomeData(id: string): Observable<GetSomeDataResponse> {
const endpoint = new URL(ENDPOINTS.get(`get_some_data`));
return this.http.get({
url: endpoint.toString(),
cacheMins: DEFAULT_CACHE_MINS,
});
}
putSomeData(id: string, foo: Foo, bar: Bar): Observable<PutSomeDataResponse> {
const endpoint = new URL(ENDPOINTS.get(`post_some_data`));
const body: PutSomeDataRequest = {
id,
foo,
bar,
};
return this.http.post({
url: endpoint.toString(),
body,
});
}
}
Short self plug: If you’re looking for an extensive yet simple-to-learn SCSS framework, check out my project Cirrus!