edit-icon download-icon

Classic scenarios

Last Updated: Dec 21, 2017

Blacklist

ApsaraDB for Memcache is used to cache the full list of users of a website (blacklist + whitelist). This is because ApsaraDB for Memcache features a high storage cost efficiency, and the space for time policy can be applied to improve the hit rate of identifying blacklisted users, and reduce the workload of the database.

Specific method: The blacklist can be stored to ApsaraDB for Memcache in advance. When a non-blacklisted user attempts to log on to the website, the system queries the database for the blacklist if it failed to hit ApsaraDB for Memcache. In this event, the query result is empty. Then, the user is stored as a whitelisted user for ApsaraDB for Memcache to prevent cache breakdown.

  1. Key:Username Value:{Black/White, Other}

Caching of the home page and headlines

For the caching of the home page and headlines that are updated less frequently, only a few keys are accessed by massive access requests as those items are frequently accessed but few in number. When the visit volume is high, the response time may be slow and the system may even crash. Such problems cannot be resolved simply by expanding the system or load balancing.

Specific method: Create a duplicate for frequently-accessed keys to relieve the highly-concurrent single hotspot.

Key:Username1 Value:{Message}

Key:Username2 Value:{Message}

Key:Username3 Value:{Message}

Interface access frequency control

The access frequency is recorded and the use of frequently accessed interfaces is limited.

Specific method: Use the ApsaraDB for Memcache’s auto-incrementing function public int incr(string $key [, int $offset = 1 [, int $initial_value = 0 [, int $expiry = 0 ]]])to combine the called interface name, user name and current time into a key, and use value to store the access count. For each access, the system calls incr to increment automatically and permits access if the allowed number of accesses is not reached or deny the access if the number is reached. In this way, the access frequency of interfaces can be effectively controlled.

  1. Key:ApiName+User+Time Value: { count }
  2. if (ocs.incr(key, 1, 1 , 10) > 100) {
  3. Access Denied;
  4. } else {
  5. Pass;
  6. }
Thank you! We've received your feedback.