• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to read multiple values from cache at once?

#1
Hello everyone,

I am using memcached in CI and I have saved user information in cache with keys as user_1, user_2, and so on.

While reading them back from cache, I am using iteration as follows -

for ($i = 1, $i <= 10; $i++) {

$UserData = $this->cache->memcached->get("user_" . $i);

//And then process $UserData

}

But when I checked the performance, I found that it takes time due to reading the cached value in iterations.
I want to know if there is any way where I can get all cached values at once by supplying array of keys.. something like following -

for ($i = 1, $i <= 10; $i++) {
$userIDArray[] = "user_" . $i;
}
$UserData = $this->cache->memcached->get($userIDArray);

Thanks.
Reply

#2
No way as I know if you are using memcached.
If you are using Redis, you can read multiple values at once.
https://github.com/phpredis/phpredis#keys-getkeys
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.