Skip to content

Instantly share code, notes, and snippets.

@christopherbauer
Created April 30, 2023 22:08
Show Gist options
  • Save christopherbauer/7b967e69d180489c4f22ab526ac80278 to your computer and use it in GitHub Desktop.
Save christopherbauer/7b967e69d180489c4f22ab526ac80278 to your computer and use it in GitHub Desktop.
import { DataAccessLayer } from "./DataAccessLayer";
import { Service } from "./Service";
import { CacheEject, CacheFlush, CacheKeys } from "./cached";
const service = new Service(new DataAccessLayer());
const id1 = service.register({ firstName: "Chris", lastName: "Bauer" });
const id2 = service.register({ firstName: "John", lastName: "Tomson" });
const id3 = service.register({ firstName: "Tom", lastName: "Johnson" });
let tries = 0;
const getAllUsersInfo = () => {
tries++;
console.log(`/***************************************************`);
console.log(`** Execution: ${tries}`);
console.log(`***************************************************/`);
console.log(service.getUserInfo(id1));
console.log(service.getUserInfo(id2));
console.log(service.getUserInfo(id3));
};
getAllUsersInfo();
//Check how much faster the cached DAL code runs!
getAllUsersInfo();
CacheFlush();
//Slow again!
getAllUsersInfo();
const keys = CacheKeys();
CacheEject(keys[1]);
//id2 will run slower because we've ejected them from the cache
getAllUsersInfo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment