Q&A
Ask and answer questions to make information more available to wider audiences.
Liliana Low @lowliliana   30, Mar 2023 12:00 AM
Associate developer
Please help me with this test!
A developer is adding Amazon ElastiCache for Memcached to a company's existing record storage application. The developer has decided to use lazy loading based on an analysis of common record handling patterns.
Which pseudocode example will correctly implement lazy loading?

A)
record_value = db.query("UPDATE Records SET Details = {1} WHERE ID == {0}"), record_key, record_value)
cache.set (record_key, record_value)
B) 
record_value = cache.get(record_key)
if (record_value == NULL)
    record_value = db.query ("SELECT Details FROM Records WHERE ID == {0}", record_key)
    cache.set (record_key, record_value)
C)
record_value = cache.get (record_key)
db.query("UPDATE Records SET Details = {1} WHERE ID == {0}", record_key, record_value)
D)
record_value = db.query("SELECT Details FROM Records WHERE ID == {0}", record_key)
if (record_value != NULL)
   cache.set (record_key, record_value)
answers 1
 
Answer 1
James Bomengen @jamesbomengen   31, Mar 2023 10:10 AM
 B – Lazy loading is a caching strategy in which a record does not load until the record is needed. When you implement lazy loading, the application first checks the cache for a record. If the record is not present, the application retrieves the record from the database and stores the record in the cache.