开发者

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 u开发者_StackOverflowse 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜