diff --git a/src/market/RegionalMarketCache.spec.ts b/src/market/RegionalMarketCache.spec.ts deleted file mode 100644 index d311040..0000000 --- a/src/market/RegionalMarketCache.spec.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { describe, expect, test } from 'vitest' -import { RegionalMarketCache } from './RegionalMarketCache' - -describe('RegionalMarketCache', () => { - test('should cache and retrieve values', async () => { - const cache = new RegionalMarketCache(1000) - - cache.set(1, 1, 'test') - expect(cache.get(1, 1)).toBe('test') - }) - - test('should remove values', async () => { - const cache = new RegionalMarketCache(1000) - - cache.set(1, 1, 'test') - cache.remove(1, 1) - expect(cache.get(1, 1)).toBeUndefined() - }) - - test('should compute values if absent', async () => { - const cache = new RegionalMarketCache(1000) - const value = await cache.computeIfAbsent(1, 1, () => Promise.resolve('test')) - - expect(value).toBe('test') - expect(cache.get(1, 1)).toBe('test') - }) - - test('should expire values', async () => { - const cache = new RegionalMarketCache(1) - - cache.set(1, 1, 'test') - await new Promise(resolve => setTimeout(resolve, 10)) - expect(cache.get(1, 1)).toBeUndefined() - }) -}) \ No newline at end of file diff --git a/src/market/RegionalMarketCache.ts b/src/market/RegionalMarketCache.ts deleted file mode 100644 index f738aa8..0000000 --- a/src/market/RegionalMarketCache.ts +++ /dev/null @@ -1,50 +0,0 @@ -class CacheEntry { - public value: T; - public expiration: Date; - - constructor(value: T, expiration: Date) { - this.value = value; - this.expiration = expiration; - } -} - -export type ExpirationSupplier = (v: T) => Date; - -export class RegionalMarketCache { - private cache: Record>>; - private expirationSupplier: (v: T) => Date; - - constructor(expiration: ExpirationSupplier | number) { - this.cache = {}; - this.expirationSupplier = expiration instanceof Function ? expiration : () => new Date(Date.now() + expiration); - } - - public get(regionId: number, typeId: number): T | undefined { - const entry = this.cache[regionId]?.[typeId]; - - if (entry && entry.expiration > new Date()) { - return entry.value; - } - this.remove(regionId, typeId); - return undefined; - } - - public set(regionId: number, typeId: number, value: T): void { - this.cache[regionId] = this.cache[regionId] ?? {}; - this.cache[regionId][typeId] = new CacheEntry(value, this.expirationSupplier(value)); - } - - public remove(regionId: number, typeId: number): void { - delete this.cache[regionId]?.[typeId]; - } - - public async computeIfAbsent(regionId: number, typeId: number, supplier: () => (Promise | T)): Promise { - let value = this.get(regionId, typeId); - - if (!value) { - value = await supplier(); - this.set(regionId, typeId, value); - } - return value; - } -}; \ No newline at end of file diff --git a/src/market/acquisition/AcquisitionsPanel.vue b/src/market/acquisition/AcquisitionsPanel.vue index 37ddbe5..f28e55c 100644 --- a/src/market/acquisition/AcquisitionsPanel.vue +++ b/src/market/acquisition/AcquisitionsPanel.vue @@ -1,5 +1,5 @@