开发者

Caching for database questions

  • When we say caching like using memcahe or Redis, is this a 1:1 caching between the user and the cache or can we cache 1 item and use it for all user? Some items like a Friend list will be 1:1 a that is unique per user. But if i want to cache the auto complete lis开发者_运维百科t for city lookups which can be used by any user, will it just store 1 list in the cache used by all users at same time or doe it need to store 1 list per user?

  • Is it possible to cache the entire database, all the lookups, all the users, all their photos, etc using memache or redis?

  • So from the above example: a friend list will be cleared from the cache when the user logs off. But something like city auto complete will stay in the cache 24-7-365, am i correct?


It can be either - if your cache key includes a user ID that record will be for a single user.

You can cache everything if you need to, though obviously that requires quite a bit of memory, and if you are doing that it may be worth using redis or memcachedb as your primary data store instead of as a cache. You may want to do something different with photos though - you can store them as blobs, but storing them on the file system and keeping a path/URL in the database is probably more efficient.

Caching is usually independent of user sessions - instead you have either a set expiry time for each key, track time since the key was last accessed, or expire on write.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜