* Returns result. * @param {string} identifier identifier * @returns {string | Promise<string>} result
(identifier)
| 897 | * @returns {string | Promise<string>} result |
| 898 | */ |
| 899 | get(identifier) { |
| 900 | this.used.add(identifier); |
| 901 | if (this.content) { |
| 902 | return this.content.get(identifier); |
| 903 | } |
| 904 | |
| 905 | const logger = /** @type {Logger} */ (this.logger); |
| 906 | // We are in state B |
| 907 | const { lazyName } = this; |
| 908 | /** @type {string | undefined} */ |
| 909 | let timeMessage; |
| 910 | if (lazyName) { |
| 911 | // only log once |
| 912 | this.lazyName = undefined; |
| 913 | timeMessage = `restore cache content ${lazyName} (${formatSize( |
| 914 | this.getSize() |
| 915 | )})`; |
| 916 | logger.log( |
| 917 | `starting to restore cache content ${lazyName} (${formatSize( |
| 918 | this.getSize() |
| 919 | )}) because of request to: ${identifier}` |
| 920 | ); |
| 921 | logger.time(timeMessage); |
| 922 | } |
| 923 | const value = /** @type {LazyFunction} */ (this.lazy)(); |
| 924 | if ("then" in value) { |
| 925 | return value.then((data) => { |
| 926 | const map = data.map; |
| 927 | if (timeMessage) { |
| 928 | logger.timeEnd(timeMessage); |
| 929 | } |
| 930 | // Move to state C |
| 931 | this.content = map; |
| 932 | this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy); |
| 933 | return map.get(identifier); |
| 934 | }); |
| 935 | } |
| 936 | |
| 937 | const map = value.map; |
| 938 | if (timeMessage) { |
| 939 | logger.timeEnd(timeMessage); |
| 940 | } |
| 941 | // Move to state C |
| 942 | this.content = map; |
| 943 | this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy); |
| 944 | return map.get(identifier); |
| 945 | } |
| 946 | |
| 947 | /** |
| 948 | * Returns maybe a promise if lazy. |
nothing calls this directly
no test coverage detected