Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6529121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:35:59+00:00 2026-05-25T09:35:59+00:00

I am attempting to use a file as a trigger to refresh my cached

  • 0

I am attempting to use a file as a trigger to refresh my cached items. When the file is changed, I need to fire an event (every time the file changes). I’m currently using the HostFileChangeMonitor class. Here’s where a cached item gets set, using a policy to link it to a file:

private static void SetPolicy(CacheNames cacheName, CacheItem item)
    {
        string strCacheName = cacheName.ToString();
        CacheItemPolicy policy;
        if (_policies.TryGetValue(strCacheName, out policy))
        {
            _cacheObject.Set(item, policy);
            return;
        }
        policy = new CacheItemPolicy();
        List<string> filePaths = new List<string> {
            string.Format(@"{0}\{1}.txt",Config.AppSettings.CachePath,cacheName.ToString())
        };
        var changeMonitor = new HostFileChangeMonitor(filePaths);
        _cacheObject.Set(item, policy);
        changeMonitor.NotifyOnChanged(new OnChangedCallback(RefreshCache));
        policy.ChangeMonitors.Add(changeMonitor);
    }

The NotifyOnChanged fires only once, however. Because of that, I am currently removing and then re-adding the item to the cache in the RefreshCache method called by the NotifyOnChanged:

private static void RefreshCache(object state)
    {
        //remove from cache
        WcfCache.ClearCache("Refreshed");
        //resubscribe to NotifyOnChanged event
        WcfCache.SetCache("Refreshed", true, CacheNames.CacheFileName);
        //grab all cache data and refresh each in parallel
}

Is there a better way to do this? Is there an event I can tap into that will ALWAYS fire (instead of just the first time like this NotifyOnChanged)? This seems pretty fragile. If the HostFileChangeMonitor doesn’t get added properly one time, the entire app’s cache will never refresh.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:36:00+00:00Added an answer on May 25, 2026 at 9:36 am

    Have you tried the FileSystemWatcher and handling its Change event?Here’s MSDN’s documentation on the subject for more detailed info.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to use a .gitignore file with negated patterns (lines starting with
I'm attempting to upload a file into a jsp and then use the file
I'm attempting to use Paramiko (Python SSH library) to read a remote file, and
I am attempting to use System.Security.Cryptography.AesManaged to encrypt a file in my .net application.
Attempting to use asp.net mvc's Action Result of File. So it would seem that
I am attempting to use Inno Setup to bootstrap a WiX generated .msi file
I am attempting to use the Jquery file upload addon to asynchronously upload files
I have a CSV file of data which I'm attempting to use in my
I am attempting to use code-behind to support an event handler in a DataTemplate.
I am attempting to use AsyncTask to load a file of determinate length. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.