开发者

Private Cache Object in ASP.NET

开发者 https://www.devze.com 2023-02-10 07:10 出处:网络
I need to utilize the Cache object in ASP.NET to store some data with a file dependency but I can\'t have it available to the rest of the application. There could be some security violations if someon

I need to utilize the Cache object in ASP.NET to store some data with a file dependency but I can't have it available to the rest of the application. There could be some security violations if someone set the cache item to something different.

I couldn't find a way to say the cache item is private to my assembly.

I was expecting to be able to create my own new Cache(), but checking for a value, mycache["Value"] != null, is throwing an null reference exception from the inards of the object. I'm assuming because the Server.Cache object is created with some other stuff that initializes the Cache object correct开发者_JAVA百科ly.

Does anyone know how I can make an item private, or initialize my own Cache object?

EDIT: Inserting an item also throws a null reference exception. mycache.Insert("item", true)


If you mean private in the sense that you're creating a component that you will distribute to other programmers, and you want to cache stuff with your component but hide the cache item details that you're caching from programmer's prying eyes, you can't use Cache that way.

You can encrypt your cache items though. Providing your encryption scheme is secure, programmers will be able to override your cached items, but you will always be the only one who can decrypt your encrypted values. If decryption fails, then you know that the cache has been tampered with.


Technically there is no way to hide the cache from a programmatic aspect. The way to achieve something similar is to create a wrapper and force everyone to use this wrapper to extract the data. The wrapper can sit on top of the cache, and as long as everyone goes through the wrapper, it can work as expected.

But there is nothing available to privatize this unless you use a whole other construct that's instantiated and managed by the application (say EL cache for instance).

HTH.

0

精彩评论

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