Click here to Skip to main content
15,889,462 members
Home / Discussions / C#
   

C#

 
GeneralRe: Free Form Controls Pin
Jon G28-Apr-04 10:08
Jon G28-Apr-04 10:08 
GeneralRe: Free Form Controls Pin
Jon G28-Apr-04 10:14
Jon G28-Apr-04 10:14 
GeneralRe: Free Form Controls Pin
Heath Stewart28-Apr-04 10:15
protectorHeath Stewart28-Apr-04 10:15 
GeneralRe: Free Form Controls Pin
..Hubert..28-Apr-04 22:17
..Hubert..28-Apr-04 22:17 
GeneralRE: Web Service Startup Pin
mjmcinto28-Apr-04 9:12
mjmcinto28-Apr-04 9:12 
GeneralRe: RE: Web Service Startup Pin
Jesse Squire28-Apr-04 9:46
Jesse Squire28-Apr-04 9:46 
GeneralRe: RE: Web Service Startup Pin
mjmcinto28-Apr-04 10:39
mjmcinto28-Apr-04 10:39 
GeneralRe: RE: Web Service Startup Pin
Heath Stewart28-Apr-04 11:19
protectorHeath Stewart28-Apr-04 11:19 
Because you must check the cache each time you get the item from it, you'd want to encapsulate this in a method that the constructor (called when the Web Service class is instantiated) and your methods can call to get the object from the cache:
[WebService]
public class MyWebService : WebService
{
  public MyWebService()
  {
    // Initialize to boost performance of first call.
    GetContent();
  }
  [WebMethod]
  public void DoSomething()
  {
    string content = GetContent();
    if (content != null)
      // do something with the content of the file that's cached.
  }
  private string GetContent()
  {
    string content = (string)Context.Cache[CacheName];
    if (content == null)
    {
      string path = Server.MapPath("/path/to/virtual/file.txt");
      using (StreamReader reader = new StreamReader(path))
      {
        content = reader.ReadToEnd();
        reader.Close();
      }
      Context.Cache.Add(
        CacheName,
        content,
        new CacheDependency(path),
        Cache.NoAbsoluteExpiration,
        Cache.NoSlidingExpiration,
        CacheItemPriority.Default,
        null);
    }
    return content;
  }
  private const string CacheName = "CONTENT";
}
This places the content of a file in the cache. The CacheDependency makes sure that if the file is changed, the cache item is invalidated. This means that null would be returned when trying to get the item from the cache. In this case, you read-in the content of that file and re-add it to the cache.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: RE: Web Service Startup Pin
je_gonzalez28-Apr-04 11:03
je_gonzalez28-Apr-04 11:03 
GeneralRe: RE: Web Service Startup Pin
mjmcinto28-Apr-04 11:25
mjmcinto28-Apr-04 11:25 
GeneralRe: RE: Web Service Startup Pin
mjmcinto29-Apr-04 4:00
mjmcinto29-Apr-04 4:00 
QuestionHow can I change (Windows form) ListView item height? Pin
Arnaud Bui28-Apr-04 7:09
Arnaud Bui28-Apr-04 7:09 
AnswerRe: How can I change (Windows form) ListView item height? Pin
Heath Stewart28-Apr-04 8:25
protectorHeath Stewart28-Apr-04 8:25 
GeneralQuestion on TabControl and context menu Pin
Flack28-Apr-04 6:57
Flack28-Apr-04 6:57 
GeneralRe: Question on TabControl and context menu Pin
Heath Stewart28-Apr-04 8:17
protectorHeath Stewart28-Apr-04 8:17 
Generallive video Pin
Anonymous28-Apr-04 6:46
Anonymous28-Apr-04 6:46 
GeneralRe: live video Pin
Heath Stewart28-Apr-04 8:14
protectorHeath Stewart28-Apr-04 8:14 
GeneralRe: live video Pin
Anonymous29-May-04 8:16
Anonymous29-May-04 8:16 
Generalremoting : singleton vs singlecall Pin
Anonymous28-Apr-04 5:57
Anonymous28-Apr-04 5:57 
GeneralRe: remoting : singleton vs singlecall Pin
Heath Stewart28-Apr-04 6:27
protectorHeath Stewart28-Apr-04 6:27 
Questionhow do i loop controls on webpage Pin
robmays28-Apr-04 5:25
robmays28-Apr-04 5:25 
AnswerRe: how do i loop controls on webpage Pin
Heath Stewart28-Apr-04 6:25
protectorHeath Stewart28-Apr-04 6:25 
GeneralRe: how do i loop controls on webpage Pin
robmays28-Apr-04 8:15
robmays28-Apr-04 8:15 
GeneralSplitted forms and selection Pin
Gian28-Apr-04 5:17
Gian28-Apr-04 5:17 
GeneralRe: Splitted forms and selection Pin
Heath Stewart28-Apr-04 6:24
protectorHeath Stewart28-Apr-04 6:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.