Skip to content

Commit ce5cc79

Browse files
committed
refactor: remove unused cache options and related methods from Cacher class
1 parent c75a7c1 commit ce5cc79

2 files changed

Lines changed: 0 additions & 154 deletions

File tree

Lines changed: 0 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
import { ForeignKeyDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/foreign-key.ds.js';
2-
import { PrimaryKeyDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/primary-key.ds.js';
3-
import { TableStructureDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/table-structure.ds.js';
4-
import { Knex } from 'knex';
51
import { LRUCache } from 'lru-cache';
6-
import { ConnectionEntity } from '../../entities/connection/connection.entity.js';
72
import { isSaaS } from '../app/is-saas.js';
83
import { Constants } from '../constants/constants.js';
94

10-
const knexCache = new LRUCache(Constants.DEFAULT_CONNECTION_CACHE_OPTIONS);
11-
const tunnelCache = new LRUCache(Constants.DEFAULT_TUNNEL_CACHE_OPTIONS);
12-
const driverCache = new LRUCache(Constants.DEFAULT_DRIVER_CACHE_OPTIONS);
135
const invitationCache = new LRUCache(Constants.DEFAULT_INVITATION_CACHE_OPTIONS);
14-
const tableStructureCache = new LRUCache(Constants.DEFAULT_TABLE_STRUCTURE_ELEMENTS_CACHE_OPTIONS);
15-
const tableForeignKeysCache = new LRUCache(Constants.DEFAULT_TABLE_STRUCTURE_ELEMENTS_CACHE_OPTIONS);
16-
const tablePrimaryKeysCache = new LRUCache(Constants.DEFAULT_TABLE_STRUCTURE_ELEMENTS_CACHE_OPTIONS);
176
const tableReadPermissionCache = new LRUCache(Constants.DEFAULT_TABLE_PERMISSIONS_CACHE_OPTIONS);
187

198
export class Cacher {
@@ -76,129 +65,8 @@ export class Cacher {
7665
return userInvitations <= 10 && groupInvitations <= 10;
7766
}
7867

79-
public static getCachedKnex(connectionConfig): Knex {
80-
const cachedKnex = knexCache.get(JSON.stringify(connectionConfig)) as Knex;
81-
return cachedKnex ? cachedKnex : null;
82-
}
83-
84-
public static setKnexCache(connectionConfig, newKnex: Knex): void {
85-
knexCache.set(JSON.stringify(connectionConfig), newKnex);
86-
}
87-
88-
public static getTunnelCache(connection: ConnectionEntity): any {
89-
const cachedTnl = tunnelCache.get(JSON.stringify(connection));
90-
return cachedTnl ? cachedTnl : null;
91-
}
92-
93-
public static setTunnelCache(connection: ConnectionEntity, tnlObj): void {
94-
tunnelCache.set(JSON.stringify(connection), tnlObj);
95-
}
96-
97-
public static delTunnelCache(connection: ConnectionEntity): void {
98-
tunnelCache.delete(JSON.stringify(connection));
99-
}
100-
101-
public static getDriverCache(connection: ConnectionEntity): any {
102-
const cachedDriver = driverCache.get(JSON.stringify(connection));
103-
return cachedDriver ? cachedDriver : null;
104-
}
105-
106-
public static setDriverCache(connection: ConnectionEntity, newDriver): void {
107-
driverCache.set(JSON.stringify(connection), newDriver);
108-
}
109-
110-
public static delDriverCache(connection: ConnectionEntity): void {
111-
driverCache.delete(JSON.stringify(connection));
112-
}
113-
114-
public static setTableStructureCache(
115-
connection: ConnectionEntity,
116-
tableName: string,
117-
structure: Array<TableStructureDS>,
118-
): void {
119-
const connectionCopy = {
120-
...connection,
121-
};
122-
const cacheObj = JSON.stringify({ connectionCopy, tableName });
123-
tableStructureCache.set(cacheObj, structure);
124-
}
125-
126-
public static getTableStructureCache(connection: ConnectionEntity, tableName: string): Array<TableStructureDS> {
127-
const connectionCopy = {
128-
...connection,
129-
};
130-
const cacheObj = JSON.stringify({ connectionCopy, tableName });
131-
const foundStructure = tableStructureCache.get(cacheObj) as Array<TableStructureDS>;
132-
return foundStructure ? foundStructure : null;
133-
}
134-
135-
public static setTablePrimaryKeysCache(
136-
connection: ConnectionEntity,
137-
tableName: string,
138-
primaryKeys: Array<PrimaryKeyDS>,
139-
): void {
140-
const connectionCopy = {
141-
...connection,
142-
};
143-
const cacheObj = JSON.stringify({ connectionCopy, tableName });
144-
tablePrimaryKeysCache.set(cacheObj, primaryKeys);
145-
}
146-
147-
public static getTablePrimaryKeysCache(connection: ConnectionEntity, tableName: string): Array<PrimaryKeyDS> {
148-
const connectionCopy = {
149-
...connection,
150-
};
151-
const cacheObj = JSON.stringify({ connectionCopy, tableName });
152-
const foundKeys = tablePrimaryKeysCache.get(cacheObj) as Array<PrimaryKeyDS>;
153-
return foundKeys ? foundKeys : null;
154-
}
155-
156-
public static setTableForeignKeysCache(
157-
connection: ConnectionEntity,
158-
tableName: string,
159-
foreignKeys: Array<ForeignKeyDS>,
160-
): void {
161-
const connectionCopy = {
162-
...connection,
163-
};
164-
const cacheObj = JSON.stringify({ connectionCopy, tableName });
165-
tableForeignKeysCache.set(cacheObj, foreignKeys);
166-
}
167-
168-
public static getTableForeignKeysCache(connection: ConnectionEntity, tableName: string): Array<ForeignKeyDS> {
169-
const connectionCopy = {
170-
...connection,
171-
};
172-
const cacheObj = JSON.stringify({ connectionCopy, tableName });
173-
const foundKeys = tableForeignKeysCache.get(cacheObj) as Array<ForeignKeyDS>;
174-
return foundKeys ? foundKeys : null;
175-
}
176-
17768
public static async clearAllCache(): Promise<void> {
178-
const elements = [];
179-
knexCache.forEach((value, key) => {
180-
elements.push({ key, value });
181-
});
182-
for (const element of elements) {
183-
await element.value.destroy();
184-
knexCache.delete(element.key);
185-
}
186-
knexCache.clear();
187-
188-
const tunnelElements = [];
189-
tunnelCache.forEach((value, key) => {
190-
tunnelElements.push({ key, value });
191-
});
192-
for (const element of tunnelElements) {
193-
await element.value.close();
194-
tunnelCache.delete(element.key);
195-
}
196-
tunnelCache.clear();
197-
await driverCache.clear();
19869
await invitationCache.clear();
199-
await tableStructureCache.clear();
200-
await tableForeignKeysCache.clear();
201-
await tablePrimaryKeysCache.clear();
20270
await tableReadPermissionCache.clear();
20371
}
20472
}

backend/src/helpers/constants/constants.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -118,33 +118,11 @@ export const Constants = {
118118
},
119119
},
120120

121-
DEFAULT_TUNNEL_CACHE_OPTIONS: {
122-
max: 100,
123-
ttl: 1000 * 60 * 60,
124-
dispose: async (tnl: any) => {
125-
try {
126-
await tnl.close();
127-
} catch (e) {
128-
console.error('Tunnel closing error: ' + e);
129-
}
130-
},
131-
},
132-
133-
DEFAULT_DRIVER_CACHE_OPTIONS: {
134-
max: 50,
135-
ttl: 1000 * 60 * 60,
136-
},
137-
138121
DEFAULT_INVITATION_CACHE_OPTIONS: {
139122
max: 200,
140123
ttl: 1000 * 60 * 60,
141124
},
142125

143-
DEFAULT_TABLE_STRUCTURE_ELEMENTS_CACHE_OPTIONS: {
144-
max: 1000,
145-
ttl: 1000 * 60,
146-
},
147-
148126
DEFAULT_TABLE_PERMISSIONS_CACHE_OPTIONS: {
149127
max: 1000,
150128
ttl: 1000 * 10,

0 commit comments

Comments
 (0)