Django:强制重新加载文件以更新值

时间:2015-03-30 12:47:02

标签: python django file caching django-1.7

我有一个文件,我存储4位(例如“0100”),三个首先对应传感器状态。我想读这个值;它只工作一次:当我更改值时,当我在模板中显示这些值时,它们不会更新。我必须重新启动服务器以获取更新值,所以我认为这是一个缓存错误。我获取传感器状态的代码(如果你想要其他代码,比如我的视图或其他问我):

def get_sensor(s):
    if s is not None:
        if s == "open":
            if s_open == 1:
                return True
            else:
                return False

        elif s == "close":
            if s_close == 1:
                return True
            else:
                return False

        elif s == "ir":
            if s_ir == 1:
                return True
            else:
                return False

我的代码读取值(此代码有效,我在代码的另一部分使用它):

with open(data_file_path, "rb") as ft:
    f = pickle.load(ft)
s_open = f[0]
s_close = f[1]
s_ir = f[2]

那么如何更新文件中的值?如果我必须清除或禁用缓存它并不重要,它适用于小型程序。

谢谢,对不起我的英语,我是法国人。

0 个答案:

没有答案