简体   繁体   中英

Design Pattern for cache management

I have to create a COM API which basically will read some data from XML , do some processing on it and return some data as a string.

This API will be in COM DLL which will be in memory most of times.

I have created a struct to hold the data in memory which can be used as cache so as to avoid reading file every time whenever API is called.

I can create a singleton class which can do some processing and store the data in cache.Whenever data changes , it will update the cache and file both.

But this singleton class will only be utilized only when API gets called.This singleton class is not required globally. After reading several articles about singleton , its not a good practice to use singleton just for cache management.

I dont want to go for singleton , but dont have any other solution for this. Any suggestions???

as far as I understood you want a COM to be reachable from other programs so why don't make COM as "out of process". you will have one instance in memory where you can cache your data.

Basically its a combination of factory + strategy pattern. Factory to create instance and strategy to select the algorithm like getting from cache or the XML file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM