#header-inner {background-position: right !important; width: 100% !important;}

1/30/15

Cache.

Cache is idea / tool often used in Computing.

When the same data part is being retrieved, for example: from database - we can store most often retrieved values, or lastly retrieved n-values somewhere handy, in a Cache.

For example:

We have data set of 7 values: { (1,a), (2,c), (3,b), (4,a), (5,a), (6,a), (7,a) }.

We have cache that can contain n = 2 values.

We assume that accessing cache is quicker, cheaper than accessing the database. Probably very much.

We have following requests: 1,3,4,3,3,1,7,7.

This goes as follows:

- retrieving pair (1,a) from database; cache = { (1,a) }.
- retrieving pair (3,b) from database; cache = { (1,a), (3,b) }.
- retrieving pair (4,a) from database; cache = { (3,b), (4,a) }.
- retrieving pair (3,b) from cache; cache = { (4,a), (3,b) }.
- retrieving pair (3,b) from cache; cache = { (4,a), (3,b) }.
- retrieving pair (1,a) from database; cache = { (3,b), (1,a) }.
- retrieving pair (7,a) from database; cache = { (1,a), (7,a) }.
- retrieving pair (7,a) from cache; cache = { (1,a), (7,a) }.

Summarizing, with cache that can contain n = 2 values, we have 5 database requests with 3 cache hits instead of 8 database requests.

With larger cache capacity we'd reduce amount of database access requests even more.


Sources: my partial education, probably [7] as well.

See also: Linda, Optimization Triad.

No comments:

Post a Comment