Developing Microsoft Azure and Web Services — Question 45
The GetVendors() action in the ProcessedOrderController controller is querying the database each time it is run. The GetVendors() action must query the database only if the cache is null.
You need to add code to the action at line PC33 to cache the data.
Which code segment can you use? (Each correct answer presents a complete solution. Choose all that apply.)
Answer options
- A. cache.Set(new CacheItem("vendorKey", vendors), GetVendorPolicy());
- B. cache.Add("vendors", vendors, new CacheItemPolicy());
- C. cache.Add(new CacheItem("vendorKey", vendors) , GetVendorPolicy());
- D. cache.AddOrGetExisting("vendorKey", context, new CacheItemPolicy()); AC
Correct answer:
Explanation
Options A and C are correct because they properly store the vendors in the cache using a key and policy, allowing for efficient retrieval. Option B is incorrect as it uses a different key and policy that may not align with the caching strategy. Option D is also incorrect because it does not set the cache value; it only retrieves it if it exists.