文件更改时更新appfabric缓存 [英] Updating appfabric cache when file changes

查看:82
本文介绍了文件更改时更新appfabric缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这样的appfabric缓存 -

I'm using appfabric cache like this -

DataCache dataCache = dataCacheFactory.GetDefaultCache();
if (dataCache.Get("myCacheData") == null)
            {
                string path = MapPath("App_Data/CacheData.txt");

                // Open the file to read from.
                readText = File.ReadAllLines(path);
                dataCache.Put("myCacheData", readText);
            }
            else
            {
                readText = (string[])dataCache.Get("myCacheData");
            }

但是,如何确保每次CacheData.txt中的内容发生变化时,cahce值也会更新。

However, how do I ensure that everytime the contents in CacheData.txt changes, the cahce value also gets updated.

我错误地使用了这个吗?

Am I using this incorrectly?

谢谢!

咖啡

推荐答案

'CacheData.txt'文件内容特定于您的应用程序,对吗?将项目添加到缓存时,可以将到期时间设置为您认为可以修改内容的值。当每个项目到期时,您将使用最新的文件
内容更新缓存。根据设置的时间段,我可能会在一段时间内获得陈旧数据。如果这对您有用,请告诉我。

'CacheData.txt' file contents are specific to your application , right ? When you add item to the cache you can set expiry to a value that you think the contents can get modified. When each time item gets expired you will update the cache with latest file contents. Depending on the period set there might me time period you get stale data. Let me know if this work for you.

谢谢

Arun


这篇关于文件更改时更新appfabric缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆