none
Controlling CacheItemPolicy properties from your config file - is it possible? RRS feed

  • Question

  • With reference to the System.Runtime.Caching class in .NET 4.0 it seems possible to only set a limited number of things in the configuration file to wit:

    • name
    • polling interval
    • the amount of memory that that cache is allowed to consume
    • the percentage of memory that needs to be hit before the cache will be scavenged

    A sample section is shown below:

    <system.runtime.caching> <memoryCache> <namedCaches> <add name="NameOfMyCache" pollingInterval="00:05:00" cacheMemoryLimitMegabytes="0" physicalMemoryLimitPercentage="0"/> </namedCaches> </memoryCache> </system.runtime.caching>

    However it appears none of the really useful items (IMHO!) are controllable from the config file. These are the options that are all in the CacheItemPolicy class such as AbsoluteExpiration, SlidingExpiration and Priority (I can understand how the Callback functions aren't exposed although I would expect to see some options as to what to do in the event that these were called)

    The question is, is it possible to do this from a config file without going away and rolling your own custom sections?


    Sunt ludi et ioci dum aliquis oculo nocet.

    Wednesday, May 2, 2012 9:53 AM

Answers

  • Hi Noonand,

    Welcome to the MSDN Forum.

    So far, I think this is not easy in .net 4.0.

    Please take a look at this documentation: http://msdn.microsoft.com/en-us/library/dd941872.aspx 

    There are only the four attributes you have mentioned, and no more. 

    AbsoluteExpiration, SlidingExpiration and Priority are designed for CacheItemPolicy object which can be related to MemoryCache object. 

    One cache object can dynamically bind to different cache policy object. 

    And you can report this request to the connect site: http://connect.microsoft.com/VisualStudio/ To let Microsoft knows. 

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, May 4, 2012 2:50 AM
    Moderator

All replies

  • Hi Noonand,

    Welcome to the MSDN Forum.

    So far, I think this is not easy in .net 4.0.

    Please take a look at this documentation: http://msdn.microsoft.com/en-us/library/dd941872.aspx 

    There are only the four attributes you have mentioned, and no more. 

    AbsoluteExpiration, SlidingExpiration and Priority are designed for CacheItemPolicy object which can be related to MemoryCache object. 

    One cache object can dynamically bind to different cache policy object. 

    And you can report this request to the connect site: http://connect.microsoft.com/VisualStudio/ To let Microsoft knows. 

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, May 4, 2012 2:50 AM
    Moderator
  • Hi noonand2,

    I agree with Mike. Me too didn't find a way to handle CacheItemPolicy from config. 


    Regards, http://shwetamannjain.blogspot.com

    Friday, May 4, 2012 1:29 PM