Skip to content

Commit

Permalink
🐛 fix(cache): git memory cache clearing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed Dec 17, 2023
1 parent 70fc7c9 commit fb7ea07
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
10 changes: 7 additions & 3 deletions src/backend/lib/cache/AbstractCacheService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ export abstract class AbstractCacheService {
return `__dp__:${key}`;
}

abstract pullItem<T>(key: string): Promise<T | undefined>;
protected abstract pullItem<T>(key: string): Promise<T | undefined>;

abstract persistData(key: string, data: unknown): Promise<void>;
protected abstract persistData(key: string, data: unknown): Promise<void>;

abstract clearItem(key: string): Promise<void>;
protected abstract _clearItem(key: string): Promise<void>;

async clearItem(rawKey: string) {
await this._clearItem(this.prefixKey(rawKey));
}

abstract purge(): Promise<void>;

Expand Down
10 changes: 3 additions & 7 deletions src/backend/lib/cache/MemoryCacheAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,20 @@ export class MemoryCacheAdaptor extends AbstractCacheService {
MemoryCacheAdaptor.data = {};
}

private getData(): Record<string, unknown> {
return MemoryCacheAdaptor.data;
}

async setup() {
noop();
}

async pullItem<T>(key: string): Promise<T | undefined> {
return this.getData()[key] as T;
return MemoryCacheAdaptor.data[key] as T;
}

async persistData(key: string, data: unknown): Promise<void> {
MemoryCacheAdaptor.data[key] = data;
}

async clearItem(key: string) {
delete this.getData()[key];
async _clearItem(key: string) {
delete MemoryCacheAdaptor.data[key];
}

async purge() {
Expand Down
2 changes: 1 addition & 1 deletion src/backend/lib/cache/RedisCacheAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class RedisCacheAdaptor extends AbstractCacheService {
).set(key, JSON.stringify(data), { EX: 60 * 60 }); // I hour
}

async clearItem(key: string) {
async _clearItem(key: string) {
await (await this.getRedisInstance()).del(key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { getDbConnection } from "../connection/db";
import { AbstractConfigDataPersistenceService } from "./AbstractConfigDataPersistenceService";
import { ConfigDomain } from "./types";
import { CONFIG_TABLE_PREFIX } from "./constants";
import { createMetaData, updateMetaData } from "./portal";

const CONFIG_TABLE_NAME = CONFIG_TABLE_PREFIX("config");

export class DatabaseConfigDataPersistenceAdaptor<
T
> extends AbstractConfigDataPersistenceService<T> {
Expand Down Expand Up @@ -140,7 +140,7 @@ export class DatabaseConfigDataPersistenceAdaptor<
.update({
value: JSON.stringify(value),
updated_at: new Date(),
// TODO updated_by
...updateMetaData(),
});
if (affectedRowsCount === 0) {
await (
Expand All @@ -151,8 +151,7 @@ export class DatabaseConfigDataPersistenceAdaptor<
value: JSON.stringify(value),
created_at: new Date(),
updated_at: new Date(),
// TODO updated_by
// TODO created_by
...createMetaData(),
});
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/backend/lib/config-persistence/portal/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type { PortalConfigDomain } from "./main/types";

export const FOR_CODE_COV = 1;

export { updateMetaData, createMetaData } from "./main";
7 changes: 7 additions & 0 deletions src/backend/lib/config-persistence/portal/main/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const createMetaData = () => {
return {};
};

export const updateMetaData = () => {
return {};
};

0 comments on commit fb7ea07

Please sign in to comment.