开发者

Is Many requests to cache efficient?

when someone visits my webpage I have about 100 requests to C# cache. Do you think I would be better off just getting the information from the d开发者_如何学Pythonatabase? because if I make a database call it is just one round trip to the database. But If I try to call this information from cache I have to make many round trips to the cache.


In memory lookups are almost always faster than hopping the network to query the database.

You should also consider more than the time of that single request. Even if that single request is longer doing the 100 in memory lookups (which it won't unless your data structures are inefficient), consider the bottleneck. The database always becomes the single bottleneck in a system that can scale out. By caching in memory, you let the system breath and allow it to scale by adding more front end servers.

But caches are not without their own problems. Lifetime is always a challenge - especially if you require the data to updated quickly if changed.

Caches are also a source of bugs. If you need to update the data and your app scales out, you can bounce around in farm and get inconsistent answers. That can be minimized with cluster affinity or it may not even be an issue if the data doesn't change frequently or it's not critical to be up to date.


In-memory caches exist because a request to memory is nearly always quicker than a network request. Once you have the data in a cache, the only reason for re-querying the database is if you believe the data in your cache is out of date.

That said, if you are querying your cache many times, I don't see how this could this be reduced to a single database query (unless you are obtaining data from your cache by row or field.)

Regardless, multiple trips to memory should still be far quicker than refreshing from the database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜