tags:

views:

598

answers:

1

I have a C# service which is not an ASP.NET application, but uses a singleton instance of of class HttpRuntime to cache items in its cache member. The singleton is created like this:

static private System.Web.HttpRuntime _httpRuntime = new HttpRuntime();

I want to set its maximum memory usage so I have the following in the app's config file service.exe.config:

<configuration>
 <caching>
    <cache privateBytesLimit= "50000000"   privateBytesPollTime = "00:01:00"/>
 </caching>
</configuration>

This doesn't seem to have any effect. Instead of setting it to 50MB, when I look in HttpRuntime.Cache.EffectivePrivateBytesLimit it is 720 MB.

What am I doing wrong?

+2  A: 

You are not using the correct cache element. According to the documentation the EffectivePrivateBytesLimit property can be set with the privateBytesLimit attribute of the cache Element for caching (ASP.NET Settings Schema) element in the application's configuration file;

<configuration>
  <system.web>
    <caching>
      <cache privateBytesLimit="10000000" privateBytesPollTime="00:01:00" />
    </caching>
  </system.web>
</configuration>
Darin Dimitrov
That worked! Thanks!
Carlos A. Ibarra