Skip to main content
Notice removed Draw attention by lurkerbelow
Bounty Ended with vaughandroid's answer chosen by lurkerbelow
Notice added Draw attention by lurkerbelow
Bounty Started worth 50 reputation by lurkerbelow
Tweeted twitter.com/#!/StackProgrammer/status/290398590986248192

Shared Cache - Invalidation Best PractisePractice

I'd like to know what would be a better approach to invalidate/update cache objects.

Prerequisites

  • Having remote memcached server (serving as cache for muliplemultiple applications)
  • All servers are hosted by azure (affinity regions, same datacentersdata centers)
  • Cache object size ranges from 200 bytes up to a 50 kilobytes

Approach 1 (store in cache asap)

  1. Object A is created -> store in database and store in cache
  2. Object A requested by client -> check cache for existence, otherwise fetch from database and store in cache
  3. Object A gets updated -> store in database, store in cache
**Approach 1 (store in cache asap)**
1. Object A is created -> store in database and store in cache 2. Object A requested by client -> check cache for existence, otherwise fetch from database and store in cache 3. Object A gets updated -> store in database, store in cache

Approach 1 seems to be more straightforward. If something is created, put in the cache asap. Regardless of someone will need it.


Approach 2 (lazy cache store)

  1. Object A is created -> store in database
  2. Object A requested by client -> check cache for existence, otherwise fetch from database and store in cache
  3. Object A gets updated -> store in database, delete key in cache
**Approach 2 (lazy cache store)**
1. Object A is created -> store in database 2. Object A requested by client -> check cache for existence, otherwise fetch from database and store in cache 3. Object A gets updated -> store in database, delete key in cache

Approach 2 seems to be more memory-aware. In this approach only requested items go to cache.

 

Question 1: In mind of performance, what would be a better approach? Memory nor CPU do not count yet.

Question 2: Are my thoughts a kind of premature optimization?

Question 3: Any other thoughts? Other approaches?

 
**Question 1:** In mind of performance, what would be a better approach? Memory nor CPU do not count yet.

**Question 2:** Are my thoughts a kind of premature optimization?

**Question 3:** Any other thoughts? Other approaches?

Shared Cache - Invalidation Best Practise

I'd like to know what would be a better approach to invalidate/update cache objects.

Prerequisites

  • Having remote memcached server (serving as cache for muliple applications)
  • All servers are hosted by azure (affinity regions, same datacenters)
  • Cache object size ranges from 200 bytes up to a 50 kilobytes

Approach 1 (store in cache asap)

  1. Object A is created -> store in database and store in cache
  2. Object A requested by client -> check cache for existence, otherwise fetch from database and store in cache
  3. Object A gets updated -> store in database, store in cache

Approach 1 seems to be more straightforward. If something is created, put in the cache asap. Regardless of someone will need it.


Approach 2 (lazy cache store)

  1. Object A is created -> store in database
  2. Object A requested by client -> check cache for existence, otherwise fetch from database and store in cache
  3. Object A gets updated -> store in database, delete key in cache

Approach 2 seems to be more memory-aware. In this approach only requested items go to cache.

 

Question 1: In mind of performance, what would be a better approach? Memory nor CPU do not count yet.

Question 2: Are my thoughts a kind of premature optimization?

Question 3: Any other thoughts? Other approaches?

Shared Cache - Invalidation Best Practice

I'd like to know what would be a better approach to invalidate/update cache objects.

Prerequisites

  • Having remote memcached server (serving as cache for multiple applications)
  • All servers are hosted by azure (affinity regions, same data centers)
  • Cache object size ranges from 200 bytes up to a 50 kilobytes

**Approach 1 (store in cache asap)**
1. Object A is created -> store in database and store in cache 2. Object A requested by client -> check cache for existence, otherwise fetch from database and store in cache 3. Object A gets updated -> store in database, store in cache

Approach 1 seems to be more straightforward. If something is created, put in the cache asap. Regardless of someone will need it.


**Approach 2 (lazy cache store)**
1. Object A is created -> store in database 2. Object A requested by client -> check cache for existence, otherwise fetch from database and store in cache 3. Object A gets updated -> store in database, delete key in cache

Approach 2 seems to be more memory-aware. In this approach only requested items go to cache.

 
**Question 1:** In mind of performance, what would be a better approach? Memory nor CPU do not count yet.

**Question 2:** Are my thoughts a kind of premature optimization?

**Question 3:** Any other thoughts? Other approaches?
Source Link
lurkerbelow
  • 1k
  • 1
  • 10
  • 19

Shared Cache - Invalidation Best Practise

I'd like to know what would be a better approach to invalidate/update cache objects.

Prerequisites

  • Having remote memcached server (serving as cache for muliple applications)
  • All servers are hosted by azure (affinity regions, same datacenters)
  • Cache object size ranges from 200 bytes up to a 50 kilobytes

Approach 1 (store in cache asap)

  1. Object A is created -> store in database and store in cache
  2. Object A requested by client -> check cache for existence, otherwise fetch from database and store in cache
  3. Object A gets updated -> store in database, store in cache

Approach 1 seems to be more straightforward. If something is created, put in the cache asap. Regardless of someone will need it.


Approach 2 (lazy cache store)

  1. Object A is created -> store in database
  2. Object A requested by client -> check cache for existence, otherwise fetch from database and store in cache
  3. Object A gets updated -> store in database, delete key in cache

Approach 2 seems to be more memory-aware. In this approach only requested items go to cache.

Question 1: In mind of performance, what would be a better approach? Memory nor CPU do not count yet.

Question 2: Are my thoughts a kind of premature optimization?

Question 3: Any other thoughts? Other approaches?