We have a webapp which uses memcache to store objects temporally. We are adding background jobs to cleanup the cache (not based on time based expiration that comes with memcache). Since we have multiple instances of the webapp running, we want to make sure that only one instance is doing the cleanup at any point. So we decided to keep a flag in memcached allowing only one instance to run. Now the question.
I am just storing a flag, it could be an int, String, boolean, heck...even just a char. However queries from memcached returns Objects, which will have to casted to whatever type I pick. If I pick boolean than the object will have to be casted to lang.Boolean which might be more work than just a String.
Whic开发者_运维百科h type would you pick?
Thanks.
I would pick the type which most accurately represents the type of data I'm trying to store. It sounds like that would be a Boolean.
It seems highly unlikely that the cost of a cast is going to be the bottleneck here. Why are you even bothered about that portion of it? Do you have any measurements/benchmarks to suggest it will make a meaningful difference?
The type is pretty much irrelevant. You might want to try encoding it as null/not-null. That way you don't have to cast.
It probably will amount to a rounding error on the total time of the call, especially with a cache look up. If it's a big deal, I'd look to reducing the number of times it's called rather than shorting the execution time.
精彩评论