Last post Feb 19, 2018 07:08 AM by Brando ZWZ
Feb 18, 2018 02:40 AM|Gichan Kim|LINK
I am having two issues regarding caching.
I am using EF 6. and have a table named like "memberConfig" which has many fields of member like latLng, lastAccessTime, ..
I am writing current time to lastAccessTime field in every api call. like
var memberConfig = db.memberConfig.find(memNo);
memberConfig.lastAccessTime = DateTime.Now;
and there's time when I have to write members' latLng data to theirs latLng field every 10 seconds. and other people access to that latLng data.
As you guess It's kind of tracking someone's position.
I guess caching is better than accessing to database in terms of performance.
I am having an idea about using static variable or static dbcontext without database(Entity framework), or memoryCache, redis.
What's the best practice I should try in short time?
sorry for my english, I am not a native, I am not good at english.
Feb 19, 2018 07:08 AM|Brando ZWZ|LINK
Hi Gichan Kim,
In my opinion, this is related with request access to your web api.
Static variables VS memcached
Static variables are shared and thus they need to be thread-safe else you could have corruption of data whereas cache is thread-safe (at least the cache-collection is). Also, static variables will never go out of scope to you need to do memory management
whereas cache is cleared at specified times or when memory is low.
Cache involves serialization (and de-serialization) whereas static are pre-declared by data type they're going to hold (unless they're 'object').Cache offers features like invalidation callbacks, sliding or absolute expiration etc.Neither strategy scores
over each other in terms of performance but are implementation specific; you would be advised to do tests over each and go for the optimum. Obviously holding everything in the cache is not advisable either as that would effectively slow things down ultimately.
Memcached VS Redis
Redis is more powerful, more popular, and better supported than memcached. Memcached can only do a small fraction of the things Redis can do. Redis is better even where their features overlap.
If your application is small, I suggest you could choose Memcached.
If your application is large and you want to implement multiple feature, I suggest you could choose redis.
More details about the difference between redis and Memcached, you could refer to below answer.