@@ -20,6 +20,9 @@ interface PruefiWithName {
20
20
export default class FormatVersionRepository extends BlobStorageContainerBacked {
21
21
private ahbContainerName : string ;
22
22
private formatVersionContainerName : string ;
23
+ private formatVersionsCache : { versions : string [ ] ; timestamp : number } | null = null ;
24
+ private readonly CACHE_TTL = 3600000 ; // 1 hour in milliseconds
25
+
23
26
constructor ( client ?: BlobServiceClient ) {
24
27
super ( client ) ;
25
28
if ( ! process . env [ 'AHB_CONTAINER_NAME' ] ) {
@@ -35,6 +38,14 @@ export default class FormatVersionRepository extends BlobStorageContainerBacked
35
38
36
39
// Return a list of all unique format versions from the database
37
40
public async list ( ) : Promise < string [ ] > {
41
+ // Check if we have a valid cache
42
+ if (
43
+ this . formatVersionsCache &&
44
+ Date . now ( ) - this . formatVersionsCache . timestamp < this . CACHE_TTL
45
+ ) {
46
+ return this . formatVersionsCache . versions ;
47
+ }
48
+
38
49
// Initialize the database connection if not already initialized
39
50
if ( ! AppDataSource . isInitialized ) {
40
51
await AppDataSource . initialize ( ) ;
@@ -46,7 +57,15 @@ export default class FormatVersionRepository extends BlobStorageContainerBacked
46
57
. orderBy ( 'ahb.format_version' )
47
58
. getRawMany ( ) ;
48
59
49
- return formatVersions . map ( result => result . formatVersion ) ;
60
+ const versions = formatVersions . map ( result => result . formatVersion ) ;
61
+
62
+ // Update cache
63
+ this . formatVersionsCache = {
64
+ versions,
65
+ timestamp : Date . now ( ) ,
66
+ } ;
67
+
68
+ return versions ;
50
69
}
51
70
52
71
// Return a list of all pruefis for a specific format version by looking at the json files
0 commit comments