<p>I'm developing a web service whose methods will be called from a "dynamic banner" that will show a sort of queue of messages read from a sql server table.</p>

<p>The banner will have a heavy pressure in the home pages of high traffic sites; every time the banner will be loaded, it will call my web service, in order to obtain the new queue of messages.</p>

<p>Now: I don't want that all this traffic drives queries to the database every time the banner is loaded, so I'm thinking to use the asp.net cache (i.e. HttpRuntime.Cache[cacheKey]) to limit database accesses; I will try to have a cache refresh every minute or so.</p>

<p>Obviously I'll try have the messages as little as possible, to limit traffic.</p>

<p>But maybe there are other ways to deal with such a scenario; for example I could write the last version of the queue on the file system, and have the web service access that file; or something mixing the two approaches...</p>

<p>The solution is c# web service, asp.net 3.5, sql server 2000. </p>

<p>Any hint? Other approaches? </p>

<p>Thanks</p>

<p>Andrea</p>

[{'answer_id': 71237, 'author': 'Mike Becatti', 'author_id': 6617, 'author_profile': 'https://Stackoverflow.com/users/6617', 'pm_score': 2, 'selected': False, 'text': '<p>I think caching is a reasonable approach and you can take it a step further and add a SQL Dependency to it. </p>\n\n<p><a href="http://www.c-sharpcorner.com/UploadFile/mosessaur/sqlcachedependency01292006135138PM/sqlcachedependency.aspx?ArticleID=3caa7d32-dce0-44dc-8769-77f8448e76bc" rel="nofollow noreferrer">ASP.NET Caching: SQL Cache Dependency With SQL Server 2000</a></p>\n'}, {'answer_id': 71421, 'author': 'user11826', 'author_id': 11826, 'author_profile': 'https://Stackoverflow.com/users/11826', 'pm_score': 1, 'selected': False, 'text': '<p>Writing a file is a better solution IMHO - its served by IIS kernel code, w/o the huge asp.net overhead and you can copy the file to CDNs later.</p>\n\n<p>AFAIK dependency cashing is not very efficient with SQL Server 2000.</p>\n'}, {'answer_id': 71445, 'author': 'Mike Becatti', 'author_id': 6617, 'author_profile': 'https://Stackoverflow.com/users/6617', 'pm_score': 1, 'selected': False, 'text': '<p>If you go the file route, keep this in mind.</p>\n\n<p><a href="http://petesbloggerama.blogspot.com/2008/02/aspnet-writing-files-vs-application.html" rel="nofollow noreferrer">http://petesbloggerama.blogspot.com/2008/02/aspnet-writing-files-vs-application.html</a></p>\n'}, {'answer_id': 71596, 'author': 'Sklivvz', 'author_id': 7028, 'author_profile': 'https://Stackoverflow.com/users/7028', 'pm_score': 3, 'selected': True, 'text': '<p>It depends on a lot of things:</p>\n\n<ul>\n<li>If there is little change in the data (think backend with "publish" button or daily batches), then I would definitely use static files (updated via push from the backend). We used this solution on a couple of large sites and worked really well.</li>\n<li>If the data is small enough, memory caching (i.e. Http Cache) is viable, but beware of locking issues and also beware that Http Cache <strong>will not</strong> work that well under heavy memory load, because items can be expired early if the framework needs memory. I have been bitten by it before! With the above caveats, Http Cache works quite well.</li>\n</ul>\n'}, {'answer_id': 77530, 'author': 'Mitchel Sellers', 'author_id': 13279, 'author_profile': 'https://Stackoverflow.com/users/13279', 'pm_score': 0, 'selected': False, 'text': "<p>Also, one way to get around the memory limitation mentioned by Skliwz is that if you are using this service outside of the normal application you can isolate it in it's own app pool.  I have seen this done before which helps as well.</p>\n"}, {'answer_id': 81198, 'author': 'ila', 'author_id': 1178, 'author_profile': 'https://Stackoverflow.com/users/1178', 'pm_score': 0, 'selected': False, 'text': "<p>Thanks all, as the data are little in size, but the underlying tables will change, I think that I'll go the HttpCache way: I need actually a way to reduce db access, even if the data are changing (so that's the reason to not using a direct Sql dependency as suggested by @Bloodhound).</p>\n\n<p>I'll make some stress test before going public, I think.</p>\n\n<p>Thanks again all.</p>\n"}, {'answer_id': 404798, 'author': 'Sklivvz', 'author_id': 7028, 'author_profile': 'https://Stackoverflow.com/users/7028', 'pm_score': 0, 'selected': False, 'text': '<p>Of course you could (should) also use the caching features in the <a href="http://code.google.com/p/sixpack-library/" rel="nofollow noreferrer">SixPack library</a> .</p>\n\n<ul>\n<li>Forward (normal) cache, based on HttpCache, which works by putting attributes on your class. Simplest to use, but in some cases you have to wait for the content to be actually be fetched from database.</li>\n<li>Pre-fetch cache, from scratch, which, after the first call will start refreshing the cache behind the scenes, and you are guaranteed to have content without wait in some cases.</li>\n</ul>\n\n<p>More info on the <a href="http://code.google.com/p/sixpack-library/" rel="nofollow noreferrer">SixPack library homepage</a>. Note that the code (especially the forward cache) is load tested.</p>\n\n<p>Here\'s an example of simple caching:</p>\n\n<pre><code>    [Cached]\n    public class MyTime : ContextBoundObject\n    {\n            [CachedMethod(1)]\n            public DateTime Get()\n            {\n                    Console.WriteLine("Get invoked.");\n                    return DateTime.Now;\n            }\n    }\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/71201', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1178/']