Removed ProfileSnapshotService
Added `InMemoryCacheService`
This commit is contained in:
parent
6301411a86
commit
73ecbe7d2c
@ -209,6 +209,7 @@ import { CustomLocationWaveService } from "@spt/services/CustomLocationWaveServi
|
|||||||
import { DatabaseService } from "@spt/services/DatabaseService";
|
import { DatabaseService } from "@spt/services/DatabaseService";
|
||||||
import { FenceService } from "@spt/services/FenceService";
|
import { FenceService } from "@spt/services/FenceService";
|
||||||
import { GiftService } from "@spt/services/GiftService";
|
import { GiftService } from "@spt/services/GiftService";
|
||||||
|
import { InMemoryCacheService } from "@spt/services/InMemoryCacheService";
|
||||||
import { InsuranceService } from "@spt/services/InsuranceService";
|
import { InsuranceService } from "@spt/services/InsuranceService";
|
||||||
import { ItemBaseClassService } from "@spt/services/ItemBaseClassService";
|
import { ItemBaseClassService } from "@spt/services/ItemBaseClassService";
|
||||||
import { ItemFilterService } from "@spt/services/ItemFilterService";
|
import { ItemFilterService } from "@spt/services/ItemFilterService";
|
||||||
@ -227,7 +228,6 @@ import { PlayerService } from "@spt/services/PlayerService";
|
|||||||
import { PmcChatResponseService } from "@spt/services/PmcChatResponseService";
|
import { PmcChatResponseService } from "@spt/services/PmcChatResponseService";
|
||||||
import { ProfileActivityService } from "@spt/services/ProfileActivityService";
|
import { ProfileActivityService } from "@spt/services/ProfileActivityService";
|
||||||
import { ProfileFixerService } from "@spt/services/ProfileFixerService";
|
import { ProfileFixerService } from "@spt/services/ProfileFixerService";
|
||||||
import { ProfileSnapshotService } from "@spt/services/ProfileSnapshotService";
|
|
||||||
import { RagfairCategoriesService } from "@spt/services/RagfairCategoriesService";
|
import { RagfairCategoriesService } from "@spt/services/RagfairCategoriesService";
|
||||||
import { RagfairLinkedItemService } from "@spt/services/RagfairLinkedItemService";
|
import { RagfairLinkedItemService } from "@spt/services/RagfairLinkedItemService";
|
||||||
import { RagfairOfferService } from "@spt/services/RagfairOfferService";
|
import { RagfairOfferService } from "@spt/services/RagfairOfferService";
|
||||||
@ -744,7 +744,7 @@ export class Container {
|
|||||||
});
|
});
|
||||||
depContainer.register<CustomItemService>("CustomItemService", CustomItemService);
|
depContainer.register<CustomItemService>("CustomItemService", CustomItemService);
|
||||||
depContainer.register<BotEquipmentFilterService>("BotEquipmentFilterService", BotEquipmentFilterService);
|
depContainer.register<BotEquipmentFilterService>("BotEquipmentFilterService", BotEquipmentFilterService);
|
||||||
depContainer.register<ProfileSnapshotService>("ProfileSnapshotService", ProfileSnapshotService, {
|
depContainer.register<InMemoryCacheService>("InMemoryCacheService", InMemoryCacheService, {
|
||||||
lifecycle: Lifecycle.Singleton,
|
lifecycle: Lifecycle.Singleton,
|
||||||
});
|
});
|
||||||
depContainer.register<ItemFilterService>("ItemFilterService", ItemFilterService, {
|
depContainer.register<ItemFilterService>("ItemFilterService", ItemFilterService, {
|
||||||
|
52
project/src/services/InMemoryCacheService.ts
Normal file
52
project/src/services/InMemoryCacheService.ts
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import { ICloner } from "@spt/utils/cloners/ICloner";
|
||||||
|
import { inject, injectable } from "tsyringe";
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class InMemoryCacheService {
|
||||||
|
protected cacheData: Record<string, any> = {};
|
||||||
|
|
||||||
|
constructor(@inject("PrimaryCloner") protected cloner: ICloner) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store data into an in-memory object
|
||||||
|
* @param key key to store data against
|
||||||
|
* @param dataToCache - Data to store in cache
|
||||||
|
*/
|
||||||
|
public storeByKey(key: string, dataToCache: any): void {
|
||||||
|
this.cacheData[key] = this.cloner.clone(dataToCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retreve data stored by a key
|
||||||
|
* @param key key
|
||||||
|
* @returns Stored data
|
||||||
|
*/
|
||||||
|
public getDataByKey<T>(key: string): any | undefined {
|
||||||
|
if (this.cacheData[key]) {
|
||||||
|
return <T>this.cacheData[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does data exists against the provided key
|
||||||
|
* @param key Key to check for data against
|
||||||
|
* @returns true if exists
|
||||||
|
*/
|
||||||
|
public hasStoredDataByKey(key: string): boolean {
|
||||||
|
if (this.cacheData[key]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove data stored against key
|
||||||
|
* @param key Key to remove data against
|
||||||
|
*/
|
||||||
|
public clearDataStoredByKey(key: string): void {
|
||||||
|
delete this.cacheData[key];
|
||||||
|
}
|
||||||
|
}
|
@ -1,53 +0,0 @@
|
|||||||
import { ISptProfile } from "@spt/models/eft/profile/ISptProfile";
|
|
||||||
import { ICloner } from "@spt/utils/cloners/ICloner";
|
|
||||||
import { inject, injectable } from "tsyringe";
|
|
||||||
|
|
||||||
@injectable()
|
|
||||||
export class ProfileSnapshotService {
|
|
||||||
protected storedProfileSnapshots: Record<string, ISptProfile> = {};
|
|
||||||
|
|
||||||
constructor(@inject("PrimaryCloner") protected cloner: ICloner) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store a profile into an in-memory object
|
|
||||||
* @param sessionID session id - acts as the key
|
|
||||||
* @param profile - profile to save
|
|
||||||
*/
|
|
||||||
public storeProfileSnapshot(sessionID: string, profile: ISptProfile): void {
|
|
||||||
this.storedProfileSnapshots[sessionID] = this.cloner.clone(profile);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retreve a stored profile
|
|
||||||
* @param sessionID key
|
|
||||||
* @returns A player profile object
|
|
||||||
*/
|
|
||||||
public getProfileSnapshot(sessionID: string): ISptProfile | undefined {
|
|
||||||
if (this.storedProfileSnapshots[sessionID]) {
|
|
||||||
return this.storedProfileSnapshots[sessionID];
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Does a profile exists against the provided key
|
|
||||||
* @param sessionID key
|
|
||||||
* @returns true if exists
|
|
||||||
*/
|
|
||||||
public hasProfileSnapshot(sessionID: string): boolean {
|
|
||||||
if (this.storedProfileSnapshots[sessionID]) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove a stored profile by key
|
|
||||||
* @param sessionID key
|
|
||||||
*/
|
|
||||||
public clearProfileSnapshot(sessionID: string): void {
|
|
||||||
delete this.storedProfileSnapshots[sessionID];
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user