如何在预热时阻止缓存访问? [英] How to prevent cache access while it is warming up?

查看:69
本文介绍了如何在预热时阻止缓存访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我使用命令行工具预热缓存,这需要几分钟才能完成。我有使用缓存客户端获取缓存值的应用程序。我想知道如何防止客户端在缓存未加热时获取值
up。

I warm up the cache using a command line tool which takes a couple of minutes to finish. I have applications which use the cache client to get cached values. I would like to know how can i do to prevent that clients get values when the cache is not warmed up.

我将不胜感激任何建议。

I would appreciate any suggestion.

谢谢。

 

推荐答案

我不明白你为什么要这样做。您的典型缓存访问模式是否如下所示?

I don't understand why you would want to do this. Does your typical cache access pattern look like this?

var myObject = _dataCache.Get(id);

var myObject = _dataCache.Get(id);

if(myObject == null)

if (myObject == null)

{

   myObject = GetObjectFromDatabase(id);

   myObject = GetObjectFromDatabase(id);

    _dataCache.Put(id,  myObject);

   _dataCache.Put(id, myObject);

}

假设您的应用程序需要在缓存启动实用程序运行时运行,您希望应用程序在此期间执行什么操作?如果您希望应用程序不使用缓存,并且没有为该缓存密钥启动缓存,它将转到数据库,
然后将值存储在缓存中。如果您缓存启动实用程序,然后为相同的缓存键填充缓存,这是一个问题吗?

Assuming your application needs to be running while the cache priming utility runs, what do you expect your application to do during this time? If you want the app to not use the cache, and the cache isn't primed for that cache key, it will go to the database, then store the value in cache. If you cache priming utility then primes the cache for that same cache key, is that a problem?


这篇关于如何在预热时阻止缓存访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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