NCache 4.6 - Online Documentation

Adding Data With File Dependency

Following code shows how to add data with File Dependency in NCache.
       To utilize the FileDependency API, include the following namespace in your application: Alachisoft.NCache.Runtime.Dependencies.
     Product product = new Product();
            product.ProductID = 1001;
            product.ProductName = "Chai";
            string key = "Product:" + product.ProductID;
            string filepath = "C:\\tempProductList.txt";
                //Adding cache item "Product:1001" with FileDependency on file "tempProductList.txt"
                cache.Insert(key, product, new FileDependency(filepath), Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,                               CacheItemPriority.Normal);
                //Change file C:\\tempProductList.txt while program waits...
                //... and then check for its existence
                Object item = cache.Get(key);
                if (item == null)
                    //item removed due to file dependency
                    //item not removed because the file may be missing or it didn't change during given interval
            catch (OperationFailedException e)
                // handle exception
See Also