Cache - MCQ
Cache in .NET Core MCQs:
1. Which caching strategy in .NET Core is suitable for
storing frequently accessed data for the duration of the application’s
lifetime?
a) Distributed Cache
b) In-Memory Cache
c) SQL Cache
d) File System Cache
Answer: b) In-Memory Cache
Explanation: In .NET Core, In-Memory Cache is
used for storing frequently accessed data for the duration of the application's
lifetime. It stores data in the application's memory, providing fast access.
This strategy is ideal for performance optimization in scenarios where data
doesn't need to persist beyond the app's execution.
2. Which interface in .NET Core is used for working with
in-memory caching?
a) ICacheService
b) IMemoryCache
c) IDistributedCache
d) IFileCache
Answer: b) IMemoryCache
Explanation: In .NET Core, the IMemoryCache
interface is used for working with in-memory caching. It provides methods to
add, retrieve, and manage cached data in the application's memory. This
interface is essential for implementing caching in scenarios where data is
stored temporarily within the app's process.
3. Which of the following is a key feature of Distributed
Caching in .NET Core?
a) Cache data is local to the application.
b) Cache data is shared across multiple instances of the application.
c) Cache data is only available on the client-side.
d) Cache data is stored in memory on the server.
Answer: b) Cache data is shared across multiple
instances of the application.
Explanation: In .NET Core, Distributed Caching
allows cache data to be shared across multiple instances of the application,
enabling consistency in distributed environments. This approach ensures that
cached data is available to all application instances, improving scalability.
It typically uses external storage like Redis or SQL Server to store the cache.
4. Which distributed cache provider is used by default in
.NET Core for Redis?
a) RedisCacheClient
b) IDistributedCache
c) RedisCache
d) RedisConnection
Answer: b) IDistributedCache
Explanation: In .NET Core, the IDistributedCache
interface is used to work with distributed caching, including Redis. It
provides methods for caching data in a distributed manner, ensuring data
consistency across multiple instances. While Redis is a common backend for
IDistributedCache, the interface itself is not Redis-specific.
5. Which .NET Core method is used to set a cache entry in
the in-memory cache?
a) SetCache()
b) SetItem()
c) Set()
d) AddToCache()
Answer: c) Set()
Explanation: In .NET Core, the Set() method is
used to add or update a cache entry in the in-memory cache. It allows you to
store data in the cache with a specified key and value. This method is part of
the IMemoryCache interface for managing in-memory caching.
6. In .NET Core, how can you configure in-memory cache
expiration time?
a) By passing TimeSpan value in the Set() method.
b) By using the CacheTime property in the cache options.
c) By setting expiration time in the application’s configuration file.
d) Expiration time is automatically handled by the system.
Answer: a) By passing TimeSpan value in the Set()
method.
Explanation: In .NET Core, you can configure the
in-memory cache expiration time by passing a TimeSpan value in the Set()
method. This allows you to specify how long the cache entry should remain valid
before it expires. The expiration time is set directly when adding the item to
the cache.
7. What is the purpose of IDistributedCache in .NET Core?
a) Caches data for a single instance of the application.
b) Caches data across multiple application instances in a distributed system.
c) Provides temporary storage for session data only.
d) Caches data in the server’s local file system.
Answer: b) Caches data across multiple application
instances in a distributed system.
Explanation: In .NET Core, IDistributedCache
is used to cache data across multiple instances of an application in a
distributed system. It ensures that cached data is consistent and available
across different servers or instances. This is particularly useful for
scalable, cloud-based, or microservices architectures.
8. Which method of IMemoryCache is used to get the cache
entry?
a) GetEntry()
b) Retrieve()
c) Get()
d) Fetch()
Answer: c) Get()
Explanation: In .NET Core, the Get() method of
IMemoryCache is used to retrieve a cache entry by its key. It allows you
to access the stored data from the in-memory cache. If the specified key
doesn't exist, it returns a default value or null, depending on the type.
9. Which method can be used to remove an entry from the
in-memory cache in .NET Core?
a) Remove()
b) Delete()
c) Clear()
d) Evict()
Answer: a) Remove()
Explanation: In .NET Core, the Remove() method
of IMemoryCache is used to remove a specific entry from the in-memory
cache. It takes the key of the cached item as an argument and deletes the
corresponding cache entry. This method helps manage cache by clearing obsolete
or unnecessary data.
10. Which .NET Core feature allows the cache to store
data in external servers like Redis or SQL Server?
a) DistributedCache
b) MemoryCache
c) FileCache
d) AppCache
Answer: a) DistributedCache
Explanation: In .NET Core, DistributedCache
allows the cache to store data in external servers like Redis or SQL Server.
This feature ensures that cached data is available across multiple application
instances in a distributed environment. It helps maintain cache consistency and
scalability for cloud-based or multi-server applications.
11. What happens when the memory cache limit is exceeded
in .NET Core?
a) An exception is thrown.
b) Cache entries are evicted based on LRU (Least Recently Used) strategy.
c) Cache entries are permanently stored until the application is restarted.
d) The cache becomes full and no further cache entries can be added.
Answer: b) Cache entries are evicted based on LRU
(Least Recently Used) strategy.
Explanation: In .NET Core, when the memory cache
limit is exceeded, cache entries are evicted based on the Least Recently
Used (LRU) strategy. This means that the least recently accessed items are
removed to make space for new entries. It helps manage memory usage efficiently
without throwing exceptions or preventing new cache additions.
12. Which of the following is a valid Redis cache
implementation in .NET Core?
a) RedisCacheClient
b) RedisConnectionManager
c) RedisCache
d) StackExchange.Redis
Answer: c) RedisCache
Explanation: In .NET Core, RedisCache is a
valid implementation for integrating Redis caching, typically used with IDistributedCache.
It provides the necessary functionality to interact with a Redis server for
distributed caching. StackExchange.Redis is the underlying Redis client
library commonly used by RedisCache in .NET Core applications.
13. Which of the following caching mechanisms provides a
mechanism to cache data in SQL Server?
a) MemoryCache
b) DistributedCache
c) SQLCache
d) SqlServerCache
Answer: d) SqlServerCache
Explanation: In .NET Core, SqlServerCache is
the caching mechanism that allows data to be cached in SQL Server. It
implements the IDistributedCache interface and uses SQL Server as the
storage backend for distributed caching. This approach enables sharing cached
data across multiple application instances using a centralized database.
14. What is the primary benefit of using distributed
caching in a cloud-based or microservices architecture?
a) Reduces storage cost.
b) Allows data to persist even after application restarts.
c) Ensures data is shared between multiple application instances and services.
d) Automatically handles cache expiration.
Answer: c) Ensures data is shared between multiple
application instances and services.
Explanation: The primary benefit of using distributed
caching in a cloud-based or microservices architecture is that it ensures
data is shared between multiple application instances and services. This
enables consistent and efficient access to cached data across different
components of the system. It improves scalability and performance in
distributed environments by maintaining centralized cache storage.
15. How can cache entries be configured to expire after a
certain period in .NET Core’s IMemoryCache?
a) Using the SlidingExpiration property.
b) By setting the AbsoluteExpiration property.
c) Both a and b.
d) Cache expiration cannot be configured in IMemoryCache.
Answer: c) Both a and b.
Explanation: In .NET Core's IMemoryCache,
cache entries can be configured to expire using either the SlidingExpiration
or AbsoluteExpiration properties. SlidingExpiration resets the
expiration time each time the cache is accessed, while AbsoluteExpiration
sets a fixed expiration time. Both methods allow precise control over cache
expiration behavior.
16. Which .NET Core feature provides support for advanced
cache expiration and eviction policies?
a) MemoryCache
b) DistributedCache
c) SqlServerCache
d) CacheFactory
Answer: a) MemoryCache
Explanation: In .NET Core, MemoryCache
provides support for advanced cache expiration and eviction policies. It allows
configuration of various expiration strategies like AbsoluteExpiration
and SlidingExpiration, and eviction policies such as Least Recently
Used (LRU). These features help manage cache memory effectively for
performance optimization.
17. Which of the following methods is used to add data to
a distributed cache in .NET Core?
a) AddCache()
b) SetCache()
c) SetAsync()
d) PutAsync()
Answer: c) SetAsync()
Explanation: In .NET Core, the SetAsync()
method is used to add data to a distributed cache. It asynchronously stores the
cache entry in the distributed cache backend (such as Redis or SQL Server).
This method allows you to specify the key, value, and expiration for the cached
data.
18. What is the default expiration behavior for cache
entries in IMemoryCache in .NET Core if no expiration settings are provided?
a) The cache entries never expire.
b) The cache entries expire immediately.
c) The cache entries expire after 30 minutes.
d) The cache entries expire based on the system's memory usage.
Answer: a) The cache entries never expire.
Explanation: In .NET Core's IMemoryCache, if
no expiration settings are provided, the cache entries never expire by
default. This means the cached data will remain in memory until it is
explicitly removed or the application is restarted. You can configure
expiration policies like AbsoluteExpiration or SlidingExpiration
to control cache lifetimes.
19. What is the main advantage of using Redis for
distributed caching in .NET Core?
a) It provides persistent storage.
b) It automatically handles database transactions.
c) It allows for high availability and horizontal scaling.
d) It supports both memory and disk-based storage.
Answer: c) It allows for high availability and
horizontal scaling.
Explanation: The main advantage of using Redis
for distributed caching in .NET Core is that it allows for high availability
and horizontal scaling. Redis can be configured in a clustered setup,
enabling data replication and partitioning across multiple nodes. This ensures
scalability, fault tolerance, and reliable caching in distributed systems.
20. Which cache provider in .NET Core is best suited for
handling caching in a multi-server environment?
a) InMemoryCache
b) RedisCache
c) FileSystemCache
d) MemoryCache
Answer: b) RedisCache
Explanation: In .NET Core, RedisCache is best
suited for handling caching in a multi-server environment. It enables
distributed caching, allowing multiple servers to share cached data, ensuring
consistency across all instances. Redis provides high availability,
scalability, and fault tolerance, making it ideal for cloud-based and
large-scale applications.
21. Which method of IDistributedCache in .NET Core is
used to retrieve a value from the cache asynchronously?
a) GetCache()
b) GetAsync()
c) RetrieveAsync()
d) FetchAsync()
Answer: b) GetAsync()
Explanation: In .NET Core, the GetAsync() method of
IDistributedCache is used to asynchronously retrieve a value from the cache. It
allows for non-blocking retrieval of cached data, improving performance in
distributed systems. The method returns the cached value or a default value if
the key doesn't exist.
22. Which .NET Core cache provider allows for storing
cached data in memory on each server, making it appropriate for a single-server
scenario?
a) Redis
b) SQL Server
c) In-Memory Cache
d) Distributed Cache
Answer: c) In-Memory Cache
Explanation: In .NET Core, In-Memory Cache
allows for storing cached data directly in the memory of a single server,
making it ideal for single-server scenarios. It provides fast access to cached
data but is limited to that specific server's memory. This cache is suitable
for applications where data sharing across multiple servers is not required.
23. Which of the following methods is used to configure
Redis caching in a .NET Core application?
a) ConfigureRedisCache()
b) AddDistributedRedisCache()
c) UseRedisCache()
d) AddCacheOptions()
Answer: b) AddDistributedRedisCache()
Explanation: In .NET Core, to configure Redis
caching, you use the AddDistributedRedisCache() method. This method adds Redis
as the distributed cache provider, allowing the application to use Redis for
storing and retrieving cached data. It is typically called in the
ConfigureServices method of the Startup class.
24. What is the default expiration strategy for items
stored in IMemoryCache when no expiration options are provided?
a) The cache items never expire.
b) The cache items expire after 30 minutes.
c) The cache items expire after 1 hour.
d) The cache items are evicted based on memory pressure.
Answer: a) The cache items never expire.
Explanation: In IMemoryCache in .NET Core, the
default expiration strategy for cache items, when no expiration options are
provided, is that the cache items never expire. The cached data remains
in memory indefinitely unless it is explicitly removed or the application is
restarted. You can configure expiration settings like AbsoluteExpiration
or SlidingExpiration to control cache lifetimes.
25. Which method of IMemoryCache is used to retrieve the
value of a cache entry, returning a default value if the entry does not exist?
a) TryGetValue()
b) Get()
c) Find()
d) GetOrCreate()
Answer: a) TryGetValue()
Explanation:
26. Which cache provider in .NET Core allows you to
persist cache data to a SQL Server database?
a) MemoryCache
b) SqlServerCache
c) RedisCache
d) DistributedCache
Answer: b) SqlServerCache
Explanation:
27. Which method of IMemoryCache is used to remove a
cache entry by its key?
a) RemoveEntry()
b) Delete()
c) Remove()
d) Evict()
Answer: c) Remove()
Explanation:
28. What type of cache is primarily used for data that
needs to be shared across multiple application instances in .NET Core?
a) MemoryCache
b) InMemoryCache
c) DistributedCache
d) FileCache
Answer: c) DistributedCache
Explanation:
29. Which of the following methods is used to set a cache
entry in IDistributedCache in .NET Core?
a) SetCache()
b) SetAsync()
c) CacheItem()
d) AddCache()
Answer: b) SetAsync()
Explanation:
30. Which .NET Core method is used to configure in-memory
caching for the application?
a) AddMemoryCache()
b) ConfigureMemoryCache()
c) SetMemoryCache()
d) EnableMemoryCache()
Answer: a) AddMemoryCache()
Explanation:
31. Which cache expiration strategy would you use in .NET
Core to automatically remove cache entries after a fixed duration?
a) AbsoluteExpiration
b) SlidingExpiration
c) Both AbsoluteExpiration and SlidingExpiration
d) MemoryPressureExpiration
Answer: c) Both AbsoluteExpiration and
SlidingExpiration
Explanation:
32. In .NET Core, how can you configure the sliding
expiration for a cache entry in IMemoryCache?
a) By using the SetSlidingExpiration() method on the cache
options.
b) By setting SlidingExpiration in the CacheItemOptions.
c) By passing a TimeSpan to the Set() method.
d) All of the above
Answer: d) All of the above
Explanation:
33. What is the correct way to inject IMemoryCache into a
constructor in .NET Core?
a) public MyClass(IMemoryCache cache)
b) public MyClass(IInMemoryCache cache)
c) public MyClass(Cache cache)
d) public MyClass(ICacheManager cache)
Answer: a) public MyClass(IMemoryCache cache)
Explanation:
34. Which of the following is the correct syntax for
creating a new cache entry with an expiration time using IMemoryCache in .NET
Core?
a) memoryCache.Set("key", value,
TimeSpan.FromMinutes(30))
b) memoryCache.Add("key", value, new
CacheEntryOptions(TimeSpan.FromMinutes(30)))
c) memoryCache.Set("key", value, new
CacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(30)))
d) memoryCache.Set("key", value, new
CacheOptions().SetExpiration(TimeSpan.FromMinutes(30)))
Answer: c) memoryCache.Set("key", value,
new CacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(30)))
Explanation:
35. In .NET Core, what is the primary purpose of the
IDistributedCache interface?
a) Caching data on a single machine for the application's
lifetime.
b) Caching data across multiple machines and processes, useful in distributed
systems.
c) Caching session data only in a web application.
d) Caching data using custom expiration policies.
Answer: b) Caching data across multiple machines and
processes, useful in distributed systems.
Explanation:
36. Which of the following methods is used to clear all
cache entries from an IMemoryCache in .NET Core?
a) Clear()
b) Flush()
c) RemoveAll()
d) IMemoryCache does not support clearing all entries at once.
Answer: d) IMemoryCache does not support clearing all
entries at once.
Explanation:
37. Which class in .NET Core is used to provide
configuration for Redis-based distributed caching?
a) RedisConfig
b) RedisCacheOptions
c) RedisCacheClient
d) RedisDistributedCache
Answer: b) RedisCacheOptions
Explanation:
38. In .NET Core, which Redis command is used to get a
value from the cache using the Redis client?
a) Redis.Get()
b) Redis.GetValue()
c) Redis.StringGet()
d) RedisCache.Get()
Answer: c) Redis.StringGet()
Explanation:
39. Which .NET Core class is used for reading data from
the Redis cache and is part of StackExchange.Redis?
a) RedisCacheClient
b) ConnectionMultiplexer
c) RedisStringClient
d) RedisCache
Answer: b) ConnectionMultiplexer
Explanation:
40. What type of expiration policy can be set for cache
entries in Redis when using IDistributedCache in .NET Core?
a) Absolute expiration
b) Sliding expiration
c) Both a and b
d) None
Answer: c) Both a and b
Explanation:
41. In .NET Core, which caching strategy is recommended
when the data is shared between different services or application instances?
a) In-memory Cache
b) Distributed Cache
c) File System Cache
d) Local Cache
Answer: b) Distributed Cache
Explanation:
42. Which of the following is a valid expiration strategy
in IMemoryCache?
a) AbsoluteExpiration
b) SlidingExpiration
c) Both AbsoluteExpiration and SlidingExpiration
d) AbsoluteExpirationRelativeToNow
Answer: c) Both AbsoluteExpiration and
SlidingExpiration
Explanation:
44. In .NET Core, what happens when a cache entry
expires, and no access is made to it?
a) It is deleted permanently from the cache.
b) It is moved to a disk-based cache.
c) It is removed from the cache automatically.
d) It is never removed unless explicitly deleted.
Answer: c) It is removed from the cache
automatically.
Explanation:
45. Which of the following methods can be used to handle
cache item expiration in IDistributedCache?
a) SlidingExpiration
b) AbsoluteExpiration
c) SetExpiration()
d) Both a and b
Answer: d) Both a and b
Explanation:
46. Which of the following are common implementations of
IDistributedCache in .NET Core?
a) MemoryCache
b) RedisCache
c) SqlServerCache
d) Both b and c
Answer: d) Both b and c
Explanation:
47. What does CacheItemPriority determine in the context
of caching in .NET Core?
a) It defines the expiration time of the cache item.
b) It controls how the cache item is evicted in low-memory conditions.
c) It allows setting the cache item’s TTL (Time to Live).
d) It forces the cache item to always expire after a fixed time.
Answer: b) It controls how the cache item is evicted
in low-memory conditions.
Explanation:
48. Which of the following is a key advantage of using
Redis for caching in .NET Core?
a) Faster memory access than SQL Server.
b) Automatic scaling of data across instances.
c) Persistent storage of cache entries.
d) No need for external configuration or setup.
Answer: b) Automatic scaling of data across
instances.
Explanation:
49. Which of the following is NOT a valid way to store
cache entries in IDistributedCache in .NET Core?
a) As a byte array
b) As a string
c) As a JSON object
d) As an object in a specific class format
Answer: d) As an object in a specific class format
(it must be serialized to a byte array)
Explanation:
50. What type of data is typically stored in a
distributed cache in .NET Core?
a) Data that is frequently updated
b) Session data
c) Frequently accessed data shared across multiple application instances
d) Large media files
Answer: c) Frequently accessed data shared across
multiple application instances
Explanation:
51. What is the primary responsibility of the ICacheEntry
interface in .NET Core's caching system?
a) To define how cache entries are retrieved.
b) To store cache entry metadata like expiration time and priority.
c) To remove expired cache entries automatically.
d) To serialize cache entry data for storage.
Answer: b) To store cache entry metadata like
expiration time and priority.
Explanation:
52. Which method in IMemoryCache is used to create a new
cache entry, or retrieve it if it already exists?
a) GetOrCreate()
b) SetOrGet()
c) FetchOrCreate()
d) AddOrUpdate()
Answer: a) GetOrCreate()
Explanation:
53. Which of the following best describes the use of
sliding expiration in a cache?
a) It removes the cache entry after a fixed amount of time.
b) It refreshes the cache entry's expiration time whenever the item is
accessed.
c) It prevents cache entries from being evicted when memory is low.
d) It guarantees that cache items will never expire.
Answer: b) It refreshes the cache entry's expiration
time whenever the item is accessed.
Explanation:
54. How does the IDistributedCache interface improve
scalability in .NET Core applications?
a) It enables caching on a single server instance only.
b) It stores data on local machines, reducing latency.
c) It allows data to be shared across multiple application instances or
services.
d) It eliminates the need for memory management.
Answer: c) It allows data to be shared across
multiple application instances or services.
Explanation:
55. What happens if a cache entry is not found in
IMemoryCache when you attempt to retrieve it?
a) It throws an exception.
b) It returns a default value (null or default type).
c) It triggers an event.
d) It returns a cache miss error.
Answer: b) It returns a default value (null or
default type).
Explanation:
56. What is the purpose of the
SetAbsoluteExpirationRelativeToNow() method in .NET Core’s IMemoryCache?
a) It sets the expiration time as an exact date and time.
b) It sets the expiration time relative to the current time.
c) It forces the cache item to expire after a specific number of cache
accesses.
d) It disables the expiration of cache entries.
Answer: b) It sets the expiration time relative to
the current time.
Explanation:
57. What is a primary reason to use IDistributedCache
over IMemoryCache in a web application?
a) It allows data to be cached on the client-side.
b) It provides high-performance memory caching.
c) It supports cache sharing between multiple servers or application instances.
d) It stores cache in files for persistence.
Answer: c) It supports cache sharing between multiple
servers or application instances.
58. In a microservices architecture, which caching
approach should you prefer for caching data shared between services?
a) Memory-based caching
b) In-memory cache
c) Distributed caching
d) File-based caching
Answer: c) Distributed caching
Explanation:
59. Which of the following can be used to configure the
cache expiry time for Redis in .NET Core?
a) RedisCacheOptions
b) SlidingExpiration
c) AbsoluteExpiration
d) Both a and c
Answer: d) Both a and c
Explanation:
61. Which caching strategy in .NET Core is used to reduce
the number of expensive database or API calls by storing frequently accessed
data?
a) Distributed Caching
b) In-Memory Caching
c) Hybrid Caching
d) File-Based Caching
Answer: b) In-Memory Caching
Explanation:
62. What does the ICacheEntry interface provide in the
context of caching in .NET Core?
a) The ability to update the cache.
b) Metadata about the cache entry such as expiration and priority.
c) A storage container for cached data.
d) Methods for cache retrieval only.
Answer: b) Metadata about the cache entry such as
expiration and priority.
Explanation:
63. Which method in IDistributedCache can be used to
check if an item exists in the cache without retrieving it?
a) ContainsAsync()
b) ExistsAsync()
c) GetAsync()
d) KeyExistsAsync()
Answer: a) ContainsAsync()
Explanation:
64. Which of the following is a major benefit of using
Redis for caching in .NET Core?
a) Redis provides data persistence across server restarts.
b) Redis is only used for caching session data.
c) Redis requires minimal configuration for most use cases.
d) Redis does not support automatic eviction of data.
Answer: a) Redis provides data persistence across
server restarts.
Explanation:
65. Which of the following .NET Core features is most
suited for caching large datasets shared across multiple services or machines?
a) MemoryCache
b) InMemoryCache
c) DistributedCache
d) FileCache
Answer: c) DistributedCache
Explanation:
66. Which of the following is NOT a valid method to set
cache expiration in IDistributedCache?
a) AbsoluteExpiration
b) SlidingExpiration
c) RelativeExpiration
d) ExpireAfter
Answer: d) ExpireAfter
Explanation:
67. What is a cache miss in .NET Core caching?
a) When an item is found in the cache.
b) When an item is evicted from the cache.
c) When an item does not exist in the cache and needs to be fetched from the
source.
d) When a cache entry expires and is deleted automatically.
Answer: c) When an item does not exist in the cache
and needs to be fetched from the source.
Explanation:
68. Which of the following is a correct way to enable
Redis caching in a .NET Core application?
a) services.AddRedisCache()
b) services.AddDistributedRedisCache(options => {...})
c) services.AddDistributedCache().UseRedis()
d) services.ConfigureRedisCache(options => {...})
Answer: b) services.AddDistributedRedisCache(options
=> {...})
Explanation:
69. What is the main difference between absolute
expiration and sliding expiration in cache management in .NET Core?
a) Absolute expiration is based on a fixed time, while
sliding expiration is based on the time since the last access.
b) Sliding expiration is only available for distributed caches.
c) Absolute expiration refreshes the expiration each time the item is accessed.
d) Sliding expiration is used to store larger data in cache.
Answer: a) Absolute expiration is based on a fixed
time, while sliding expiration is based on the time since the last access.
Explanation:
70. Which interface is used to implement custom caching
strategies in .NET Core?
a) ICustomCache
b) IExtendedCache
c) IDistributedCache
d) ICacheProvider
Answer: c) IDistributedCache
Explanation:
71. Which of the following cache expiration strategies
automatically resets the cache expiration time every time the cache item is
accessed?
a) AbsoluteExpiration
b) SlidingExpiration
c) TimeToLive
d) FixedExpiration
Answer: b) SlidingExpiration
Explanation:
73. How does Redis differ from SQL Server in terms of
caching in .NET Core?
a) Redis is an in-memory cache, whereas SQL Server is a
disk-based storage system.
b) Redis can only cache small data, while SQL Server caches large data.
c) SQL Server is faster than Redis for caching.
d) Redis provides automatic database backups, while SQL Server does not.
Answer: a) Redis is an in-memory cache, whereas SQL
Server is a disk-based storage system.
Explanation:
74. In .NET Core, which of the following options is
available when configuring a custom cache provider for IDistributedCache?
a) Implementing ICacheProvider
b) Using a custom implementation of IDistributedCache
c) Using third-party libraries such as StackExchange.Redis
d) All of the above
Answer: d) All of the above
Explanation:
75. What happens when the memory capacity of the
IMemoryCache is reached?
a) Cache items with low priority are automatically evicted.
b) Cache items are saved to a file system to free up memory.
c) No new cache items can be added until existing items expire.
d) The system throws an out-of-memory exception.
Answer: a) Cache items with low priority are
automatically evicted.
76. Which of the following is a recommended approach when
using DistributedCache in .NET Core for session management?
a) Store session data in a SQL database.
b) Store session data in a memory cache.
c) Use IDistributedCache for storing and managing session state.
d) Session data should never be cached.
Answer: c) Use IDistributedCache for storing and
managing session state.
77. Which of the following would you use to configure the
default timeout for the Redis cache in .NET Core?
a) ConfigureRedis()
b) RedisCacheOptions
c) RedisOptions
d) AddRedisCacheTimeout()
Answer: b) RedisCacheOptions
78. How can you programmatically remove a specific cache
entry from IMemoryCache?
a) memoryCache.Remove("key")
b) memoryCache.Delete("key")
c) memoryCache.Clear("key")
d) memoryCache.Evict("key")
Answer: a) memoryCache.Remove("key")
79. What would be the best approach to cache large,
non-sensitive data that doesn't change often in .NET Core?
a) Use MemoryCache for fast access.
b) Use FileCache for better persistence.
c) Use DistributedCache for scaling across multiple servers.
d) Use in-memory cache only, without expiration settings.
Answer: c) Use DistributedCache for scaling across
multiple servers.
80. Which .NET Core caching solution is most appropriate
for caching session data in a web application that runs on multiple web
servers?
a) In-memory cache
b) Redis Cache
c) SQL Server Cache
d) File-based Cache
Answer: b) Redis Cache
81. In .NET Core, which of the following is a key
characteristic of distributed caching?
a) It is faster than in-memory caching.
b) It can be shared across multiple application instances and servers.
c) It is limited to caching small amounts of data.
d) It only works with SQL databases.
Answer: b) It can be shared across multiple
application instances and servers.
82. Which of the following is a valid IDistributedCache
implementation in .NET Core?
a) SqlServerCache
b) RedisCache
c) MemoryCache
d) LocalFileCache
Answer: b) RedisCache
83. What is the main advantage of using a distributed
cache like Redis or SQL Server cache over in-memory caching in .NET Core?
a) Faster data retrieval
b) Data can be shared across multiple servers
c) Lower memory usage
d) Simpler configuration
Answer: b) Data can be shared across multiple servers
85. In .NET Core, which type of data is best suited for
in-memory caching?
a) Data that is shared between multiple instances of the
application
b) Frequently accessed and small data that does not need to be persisted
c) Large files and static content
d) Data that needs to be cached for a long period of time
Answer: b) Frequently accessed and small data that
does not need to be persisted
86. What happens when a cache item with absolute
expiration expires in .NET Core?
a) The cache item will be refreshed automatically.
b) The cache item will be deleted from the cache.
c) The cache item will remain in the cache until it is explicitly evicted.
d) The cache item will be marked as expired but still accessible.
Answer: b) The cache item will be deleted from the
cache.
87. Which of the following classes is used to configure
the Redis cache options in a .NET Core application?
a) RedisCacheOptions
b) RedisConnectionSettings
c) RedisConfigOptions
d) DistributedRedisCacheOptions
Answer: a) RedisCacheOptions
88. Which of the following expiration policies can be
used in both IMemoryCache and IDistributedCache in .NET Core?
a) Time-to-live (TTL) expiration
b) Absolute expiration
c) Sliding expiration
d) Both b and c
Answer: d) Both b and c
89. Which of the following is the default cache store
used by AddMemoryCache() in .NET Core?
a) Disk-based storage
b) SQL Server
c) In-memory
d) Redis
Answer: c) In-memory
90. In .NET Core, which method can be used to remove an
expired cache item from IMemoryCache?
a) memoryCache.RemoveExpired()
b) memoryCache.Remove()
c) memoryCache.Clear()
d) memoryCache.Evict()
Answer: b) memoryCache.Remove()
91. Which of the following cache options should be used
when you need to store session data for a web application that is hosted on
multiple servers in .NET Core?
a) In-memory cache
b) Distributed cache
c) File cache
d) Local memory cache
Answer: b) Distributed cache
94. What is the primary reason to use distributed caching
for session state management in a web application in .NET Core?
a) To improve data retrieval speed
b) To keep session data available across different servers and instances
c) To reduce database calls for session management
d) To increase memory usage on each server
Answer: b) To keep session data available across
different servers and instances
95. Which of the following methods is used to configure
cache entry options such as absolute expiration or sliding expiration in
IMemoryCache?
a) CacheItemOptions
b) MemoryCacheOptions
c) CacheEntryOptions
d) CacheConfiguration
Answer: c) CacheEntryOptions
96. Which distributed cache solution is the most
appropriate for use in a cloud-based, scalable .NET Core application?
a) In-memory cache
b) File-based cache
c) Redis Cache
d) SQL Server cache
Answer: c) Redis Cache
98. What is the effect of setting absolute expiration in
IMemoryCache?
a) The cache entry will expire after the specified duration
from the time it was created.
b) The cache entry will expire after a fixed duration from the time it was
accessed.
c) The cache entry will never expire.
d) The cache entry will expire only when the application is restarted.
Answer: a) The cache entry will expire after the
specified duration from the time it was created.
99. What is the default behavior of IDistributedCache
when an attempt to access a non-existent key is made?
a) It returns a null value.
b) It throws a KeyNotFoundException.
c) It returns a default value.
d) It triggers an event or log message.
Answer: a) It returns a null value.
100. In .NET Core, how can you configure sliding
expiration for cache entries in IMemoryCache?
a) memoryCache.Set("key", value,
TimeSpan.FromMinutes(5));
b) cacheEntryOptions.SetSlidingExpiration(TimeSpan.FromMinutes(5));
c) cache.SetSlidingExpiration(TimeSpan.FromMinutes(5));
d) slidingExpiration.Configure(TimeSpan.FromMinutes(5));
Answer: b)
cacheEntryOptions.SetSlidingExpiration(TimeSpan.FromMinutes(5));
101. Which of the following is the primary reason to use
a distributed cache in a web application running on multiple servers in .NET
Core?
a) To store large amounts of static data locally on each
server
b) To maintain consistency of cache data across all servers
c) To increase the speed of web requests
d) To handle long-running processes more efficiently
Answer: b) To maintain consistency of cache data
across all servers
102. What type of cache should be used to store large
datasets that are frequently read but rarely modified in .NET Core?
a) In-memory cache
b) Distributed cache
c) File cache
d) Disk-based cache
Answer: b) Distributed cache
103. What is the default cache duration if no expiration
is set in IMemoryCache?
a) 30 minutes
b) The cache entry does not expire.
c) 5 minutes
d) The cache entry expires after 1 hour.
Answer: b) The cache entry does not expire.
104. What is the purpose of the Priority property in
CacheEntryOptions for memory caching in .NET Core?
a) To control when the cache entry should expire.
b) To define which items should be evicted first when memory is low.
c) To set the size of the cache entry.
d) To determine the frequency of cache refresh.
Answer: b) To define which items should be evicted
first when memory is low.
105. Which class provides methods for configuring cache
eviction policies in IMemoryCache in .NET Core?
a) MemoryCacheOptions
b) CacheEntryOptions
c) CacheEvictionOptions
d) CacheSettings
Answer: b) CacheEntryOptions
106. Which of the following methods can be used to ensure
that a cache entry expires after a certain period of time from the last access
in IMemoryCache?
a) SetSlidingExpiration()
b) SetAbsoluteExpiration()
c) SetExpirationDuration()
d) SetTimeToLive()
Answer: a) SetSlidingExpiration()
107. Which of the following is a valid way to configure
cache settings for Redis in a .NET Core application?
a) services.AddDistributedCache(options => {...})
b) services.AddDistributedRedisCache(options => {...})
c) services.ConfigureRedisCache(options => {...})
d) services.UseRedisCache(options => {...})
Answer: b) services.AddDistributedRedisCache(options
=> {...})
109. Which of the following best describes the behavior
of sliding expiration in .NET Core caching?
a) The cache item expires after a fixed duration, regardless
of access time.
b) The cache item expires after the specified duration from the last access
time.
c) The cache item never expires.
d) The cache item refreshes its expiration time after every read.
Answer: b) The cache item expires after the specified
duration from the last access time.
110. What is the purpose of using priority levels in
IMemoryCache in .NET Core?
a) To determine how much memory to allocate for the cache.
b) To assign a default expiration time for all cache entries.
c) To control which cache items are evicted first when memory is under
pressure.
d) To assign a unique key to each cache item.
Answer: c) To control which cache items are evicted
first when memory is under pressure.
111. Which of the following cache expiration policies can
be used in a distributed cache in .NET Core?
a) AbsoluteExpiration
b) SlidingExpiration
c) Time-To-Live (TTL)
d) All of the above
Answer: d) All of the above
112. Which of the following cache implementations would
you use to store user session data in a .NET Core web application?
a) IMemoryCache
b) IDistributedCache
c) FileCache
d) LocalCache
Answer: b) IDistributedCache
113. Which Redis feature allows you to automatically
expire cache entries based on a specified time-to-live (TTL)?
a) RedisKeyExpire
b) EXPIRE command
c) TimeToLive
d) TTLExpire
Answer: b) EXPIRE command
114. What does the Remove() method of IMemoryCache do in
.NET Core?
a) It automatically removes expired cache entries.
b) It forces the removal of a specific cache entry using the key.
c) It evicts all cache entries that exceed the memory limit.
d) It clears the entire cache.
Answer: b) It forces the removal of a specific cache
entry using the key.
115. In .NET Core, which interface is used to implement
custom caching providers?
a) ICacheProvider
b) IDistributedCache
c) IMemoryCache
d) ICustomCache
Answer: b) IDistributedCache
116. Which method of IDistributedCache is used to store
an item with absolute expiration in a distributed cache?
a) SetAsync()
b) SetWithAbsoluteExpirationAsync()
c) AddAsync()
d) SetAsync(key, value, options)
Answer: d) SetAsync(key, value, options)
117. What happens if a cache entry with sliding
expiration is not accessed before the expiration time?
a) The cache entry is deleted from the cache.
b) The cache entry is automatically refreshed.
c) The cache entry is marked as expired but remains in the cache.
d) The cache entry is moved to a different memory pool.
Answer: a) The cache entry is deleted from the cache.
118. Which of the following cache types would be most
appropriate for an application that needs to persist cache data beyond
application restarts in .NET Core?
a) In-memory cache
b) Distributed cache (e.g., Redis)
c) File-based cache
d) Cache in SQL Server
Answer: b) Distributed cache (e.g., Redis)
119. Which cache solution provides built-in data
persistence to ensure that cached data remains available after a system restart
in .NET Core?
a) In-memory cache
b) Distributed cache (Redis)
c) SQL Server cache
d) MemoryCache
Answer: b) Distributed cache (Redis)
120. Which of the following approaches is NOT recommended
for caching sensitive data in .NET Core?
a) Use encrypted cache entries.
b) Use distributed cache solutions like Redis with encryption.
c) Store unencrypted sensitive data in memory cache for faster access.
d) Use expiration policies and eviction strategies to limit sensitive data
retention.
Answer: c) Store unencrypted sensitive data in memory
cache for faster access.
121. Which of the following is a recommended practice
when using caching in a distributed system with multiple instances of an
application in .NET Core?
a) Using an in-memory cache in each instance of the
application.
b) Using a distributed cache solution like Redis or SQL Server to ensure data
consistency.
c) Avoiding cache entirely in favor of direct database calls.
d) Storing large static data in the cache to reduce memory consumption.
Answer: b) Using a distributed cache solution like
Redis or SQL Server to ensure data consistency.
122. Which class in .NET Core provides the Set() and
Get() methods for managing distributed cache entries?
a) MemoryCache
b) RedisCache
c) DistributedCache
d) IDistributedCache
Answer: d) IDistributedCache
123. Which of the following methods can be used to set a
value in the distributed cache for a specified expiration time in .NET Core?
a) SetAsync()
b) AddAsync()
c) PutAsync()
d) StoreAsync()
Answer: a) SetAsync()
124. In .NET Core, what happens when you try to retrieve
a value from a cache that does not exist in IMemoryCache or IDistributedCache?
a) It throws a CacheMissException.
b) It returns null (or a default value for the data type).
c) It retries fetching the data from the database.
d) It triggers an event to handle the cache miss.
Answer: b) It returns null (or a default value for
the data type).
125. How can you configure the priority level for cache
eviction in IMemoryCache?
a) Use CacheItemPriority enum with CacheEntryOptions
b) Use CacheEvictionPolicy enum with MemoryCacheOptions
c) Use EvictionPolicy property in CacheEntryOptions
d) Use RemovePriority() method to set priority levels
Answer: a) Use CacheItemPriority enum with
CacheEntryOptions
126. Which of the following types of expiration ensures
that a cache entry remains valid for a specific time period after it is first
added in IMemoryCache?
a) Sliding Expiration
b) Absolute Expiration
c) Relative Expiration
d) Time-to-Live (TTL)
Answer: b) Absolute Expiration
127. Which of the following methods is used to remove all
entries from the cache in IMemoryCache?
a) RemoveAll()
b) Clear()
c) EvictAll()
d) Flush()
Answer: b) Clear()
128. Which of the following distributed cache providers
is recommended for a high-performance, low-latency caching solution in a .NET
Core application?
a) SQL Server
b) In-memory cache
c) Redis Cache
d) Azure Blob Storage
Answer: c) Redis Cache
129. Which cache policy should be used to store data in
the cache for a fixed period from the time of access in .NET Core?
a) Sliding expiration
b) Absolute expiration
c) Time-to-live (TTL)
d) Immediate eviction
Answer: a) Sliding expiration
130. Which of the following statements is false regarding
distributed caching in .NET Core?
a) Distributed caching allows data to be shared across
multiple instances of an application.
b) Distributed caches are ideal for storing session data in large-scale
applications.
c) Distributed caching requires additional configuration for data persistence.
d) Distributed caching can only be used with SQL Server as the cache provider.
Answer: d) Distributed caching can only be used with
SQL Server as the cache provider.
131. What should be done to ensure that sensitive data in
the cache is encrypted in .NET Core?
a) Use the built-in Encrypt() method provided by
IDistributedCache.
b) Encrypt sensitive data before storing it in the cache and decrypt it when
retrieving it.
c) Use a third-party encryption library to encrypt data when adding it to the
cache.
d) Encryption is not necessary in caching.
Answer: b) Encrypt sensitive data before storing it
in the cache and decrypt it when retrieving it.
132. In .NET Core, which feature of Redis cache allows it
to automatically remove expired cache items?
a) Cache eviction
b) Key expiration
c) Sliding expiration
d) Time-to-live (TTL)
Answer: b) Key expiration
133. Which method in IDistributedCache would you use to
remove an item from the distributed cache?
a) RemoveAsync()
b) DeleteAsync()
c) EvictAsync()
d) ClearAsync()
Answer: a) RemoveAsync()
134. Which configuration setting in IDistributedCache
ensures cache data is stored persistently even if the application restarts?
a) MemoryCache
b) Redis Cache
c) SQL Server Cache
d) Persistent storage is not available in distributed caches.
Answer: b) Redis Cache
136. Which of the following cache policies allows cache
data to expire after a fixed period, regardless of when it was accessed in
IMemoryCache?
a) Sliding expiration
b) Absolute expiration
c) Time-to-live (TTL)
d) Cache eviction
Answer: b) Absolute expiration
137. In .NET Core, which of the following caching
strategies is most suitable for storing large objects in a multi-instance
application?
a) In-memory caching
b) Distributed caching with Redis or SQL Server
c) File-based caching
d) Using a local database for caching
Answer: b) Distributed caching with Redis or SQL
Server
138. What is the default expiration time for cache
entries when using IDistributedCache in .NET Core if no expiration is
explicitly set?
a) 5 minutes
b) 1 hour
c) 30 minutes
d) No expiration, the data remains until removed manually
Answer: d) No expiration, the data remains until
removed manually
139. Which of the following IDistributedCache methods is
used to set cache data asynchronously in .NET Core?
a) PutAsync()
b) AddAsync()
c) SetAsync()
d) StoreAsync()
Answer: c) SetAsync()
140. Which of the following distributed cache solutions
supports data persistence beyond application restarts in .NET Core?
a) In-memory cache
b) SQL Server Cache
c) Redis Cache
d) All of the above
Answer: c) Redis Cache
141. Which caching strategy in .NET Core allows cache
data to expire after a specific period of time from when it was last accessed?
a) Absolute Expiration
b) Sliding Expiration
c) Time-To-Live
d) Immediate Expiration
Answer: b) Sliding Expiration
142. In .NET Core, which of the following classes can be
used to configure the options for memory caching?
a) DistributedCacheOptions
b) MemoryCacheOptions
c) CacheConfiguration
d) CacheEntryOptions
Answer: b) MemoryCacheOptions
143. Which Redis feature allows you to set the maximum
number of entries in a cache to ensure that the cache doesn’t grow
indefinitely?
a) RedisKeyLimit
b) MaxCacheSize
c) Maxmemory Policy
d) KeyExpirationPolicy
Answer: c) Maxmemory Policy
144. Which of the following is NOT a valid method for
setting cache entries in Redis for .NET Core distributed caching?
a) SetAsync()
b) AddAsync()
c) StoreAsync()
d) PutAsync()
Answer: d) PutAsync()
145. What is the default cache expiration behavior for
items stored in IDistributedCache if no expiration is set?
a) Cache items are set to expire after 1 minute.
b) Cache items do not expire unless explicitly set.
c) Cache items are removed after 10 minutes.
d) Cache items expire after 30 minutes.
Answer: b) Cache items do not expire unless
explicitly set.
146. Which of the following methods is used to add a
cache entry to the distributed cache in .NET Core?
a) SetAsync()
b) AddAsync()
c) InsertAsync()
d) StoreAsync()
Answer: b) AddAsync()
147. Which of the following cache implementations would
be best suited for storing user session data in a highly available, distributed
environment in .NET Core?
a) Local memory cache
b) In-memory cache
c) Redis distributed cache
d) SQL Server cache
Answer: c) Redis distributed cache
148. Which of the following is the primary reason to use
distributed caching in a web application running on multiple servers?
a) To share cached data across all instances of the
application.
b) To decrease the overall CPU usage of the servers.
c) To store cached data on the client-side.
d) To improve data consistency for session management.
Answer: a) To share cached data across all instances
of the application.
149. What is the recommended approach to improve the
performance of large-scale applications by caching in .NET Core?
a) Use in-memory caching exclusively to keep the cache close
to the application.
b) Use a distributed cache solution like Redis to manage cache across multiple
servers.
c) Cache everything including large static data without any expiration.
d) Store all cache entries in a file system for efficient reading.
Answer: b) Use a distributed cache solution like
Redis to manage cache across multiple servers.
150. What happens to cached data when the Redis server
goes down in a distributed cache configuration in .NET Core?
a) The cache data is lost permanently.
b) The data remains available as long as there are other instances of the
application running.
c) The cache entries are automatically restored from the database.
d) Redis cache will throw a timeout exception and stop caching.
Answer: a) The cache data is lost permanently.
151. Which of the following strategies is commonly used
in distributed cache to manage how cache data is stored in memory?
a) Least Recently Used (LRU)
b) First-In-First-Out (FIFO)
c) Last-In-Last-Out (LILO)
d) Cache expiration based on TTL
Answer: a) Least Recently Used (LRU)
152. In .NET Core, what is the default serialization
format for objects stored in Redis when using IDistributedCache?
a) XML
b) JSON
c) Binary
d) Plain text
Answer: b) JSON
153. What is the main advantage of using sliding
expiration for caching in .NET Core?
a) It ensures data is cached until manually evicted.
b) It allows the cache to refresh itself every time it is accessed.
c) It automatically reloads data into cache every minute.
d) It expires data on a fixed schedule regardless of usage.
Answer: b) It allows the cache to refresh itself
every time it is accessed.
154. Which of the following statements is true about
cache eviction in distributed caching systems like Redis?
a) Cache entries are evicted based on least recently
used (LRU) or similar algorithms.
b) Redis automatically increases the memory to store all cache entries forever.
c) Cache eviction strategies are not customizable in Redis.
d) Cache entries are only evicted manually by an admin.
Answer: a) Cache entries are evicted based on least
recently used (LRU) or similar algorithms.
155. Which Redis feature is used to handle cache
expiration and prevent memory overload due to the growing size of the cache?
a) Redis Keyspace Notifications
b) Redis Maxmemory Policy
c) Redis List Expiry
d) Redis Key Migration
Answer: b) Redis Maxmemory Policy
156. In a distributed cache system like Redis, how does
replication help improve cache availability?
a) Replication ensures that cache data is stored across
multiple nodes, improving availability.
b) Replication automatically ensures cache data is refreshed every minute.
c) Replication reduces the size of cache by distributing it across regions.
d) Replication stores data in a centralized location to prevent data
inconsistency.
Answer: a) Replication ensures that cache data is
stored across multiple nodes, improving availability.
157. Which of the following strategies would NOT be
appropriate for caching sensitive user information such as passwords or credit
card numbers in .NET Core?
a) Encrypt sensitive data before caching it.
b) Use SSL/TLS to secure the cache communication.
c) Store sensitive information in an unencrypted in-memory cache.
d) Set an expiration time for sensitive data cache entries.
Answer: c) Store sensitive information in an
unencrypted in-memory cache.
158. Which of the following is an appropriate method to
handle cache expiration in a distributed system with multiple web servers?
a) Use a memory cache in each web server instance, manually
invalidating the cache.
b) Use a distributed cache like Redis to synchronize expiration across all
instances.
c) Do not set cache expiration, leaving items in the cache indefinitely.
d) Use a file-based cache to store expiration timestamps for cache entries.
Answer: b) Use a distributed cache like Redis to
synchronize expiration across all instances.
159. Which method can be used to configure absolute
expiration for cache entries in .NET Core's IDistributedCache?
a) SetSlidingExpiration()
b) SetAbsoluteExpiration()
c) SetTimeToLive()
d) SetLifetime()
Answer: b) SetAbsoluteExpiration()
160. What type of caching would be most suitable for a
single-instance application with low latency requirements in .NET Core?
a) Distributed caching with Redis
b) SQL Server caching
c) In-memory caching
d) File-based caching
Answer: c) In-memory caching
161. Which of the following cache solutions is best for
high availability and data consistency across multiple application instances in
a distributed environment?
a) Local memory cache
b) In-memory cache
c) Redis cache
d) File system cache
Answer: c) Redis cache
162. Which of the following distributed cache operations
is not supported by the IDistributedCache interface in .NET Core?
a) SetAsync()
b) GetAsync()
c) RemoveAsync()
d) AddAsync()
e) PutAsync()
Answer: e) PutAsync()
163. Which of the following methods in IMemoryCache is
used to retrieve a cached item in .NET Core?
a) Get()
b) GetOrCreate()
c) Retrieve()
d) Read()
Answer: a) Get()
164. Which of the following caching policies can ensure
that an item is not removed from the cache unless explicitly evicted or
expired?
a) Sliding Expiration
b) Absolute Expiration
c) No Expiration
d) Timeout Expiration
Answer: c) No Expiration
165. In .NET Core, which method should be used to
conditionally add an item to the cache, but only if it doesn't already exist?
a) Add()
b) Set()
c) TryAdd()
d) Insert()
Answer: a) Add()
166. Which of the following Redis eviction policies
ensures that the least recently used cache entries are evicted first when
memory is exceeded?
a) volatile-lru
b) allkeys-lru
c) volatile-ttl
d) noeviction
Answer: b) allkeys-lru
167. In .NET Core, which of the following types of
expiration causes the cached data to expire after a fixed amount of time from
the moment it was added to the cache?
a) Sliding Expiration
b) Absolute Expiration
c) Cache Eviction
d) Expiration Callback
Answer: b) Absolute Expiration
168. Which of the following cache-related events is
triggered when a cache entry is evicted due to expiration or other reasons in
.NET Core?
a) EvictionCallback
b) ItemExpired
c) CacheMiss
d) CacheRefresh
Answer: a) EvictionCallback
169. What is the primary benefit of using distributed
cache like Redis over in-memory cache in a multi-instance application?
a) Faster cache lookups
b) Reduced application memory usage
c) Shared cache across all application instances
d) Better support for complex data types
Answer: c) Shared cache across all application
instances
170. Which of the following strategies prevents cache
data from being lost in case of Redis server failures?
a) Redis Persistence (RDB or AOF)
b) Redis Replication
c) Redis Cluster
d) Redis Memory Overhead
Answer: a) Redis Persistence (RDB or AOF)
171. What is the main advantage of using sliding
expiration for caching over absolute expiration in .NET Core?
a) Cached data is always refreshed when accessed.
b) Cached data is guaranteed to expire at a fixed time.
c) Sliding expiration is more efficient for short-lived data.
d) It is more useful when data must remain cached forever.
Answer: a) Cached data is always refreshed when
accessed.
172. Which of the following tools can be used to monitor
Redis cache usage and performance in a .NET Core application?
a) Redis CLI
b) Redis Monitoring Tools (e.g., RedisInsight)
c) Visual Studio Cache Profiler
d) SQL Server Management Studio
Answer: b) Redis Monitoring Tools (e.g.,
RedisInsight)
173. Which method is used to configure cache expiration
when using IDistributedCache in .NET Core?
a) SetExpiry()
b) SetCacheDuration()
c) SetAbsoluteExpiration()
d) AddCachePolicy()
Answer: c) SetAbsoluteExpiration()
174. What type of cache implementation in .NET Core would
best suit applications that store session data for users?
a) Local in-memory cache
b) Distributed in-memory cache
c) Distributed cache using Redis
d) File-based cache
Answer: c) Distributed cache using Redis
175. Which of the following Redis eviction policies
ensures that keys with set expiration times are evicted first when memory is
exceeded?
a) volatile-lru
b) allkeys-lru
c) volatile-ttl
d) noeviction
Answer: c) volatile-ttl
176. Which method in IMemoryCache is used to add cache
entries in .NET Core with an explicit expiration time?
a) Set()
b) Add()
c) Put()
d) Create()
Answer: b) Add()
177. Which of the following statements is true about
Redis caching in .NET Core?
a) Redis does not support automatic eviction of expired
keys.
b) Redis supports the use of persistent data storage options
like RDB snapshots or AOF logs.
c) Redis can only be used for session-based caching in .NET Core.
d) Redis is only available for Azure-hosted applications.
Answer: b) Redis supports the use of persistent data
storage options like RDB snapshots or AOF logs.
178. In .NET Core, which of the following is the most
efficient way to add a large object to the cache using distributed caching?
a) Serialize the object and store it as a string or binary.
b) Store the object directly without serialization.
c) Use a custom cache provider for large objects.
d) Store the object in multiple small pieces.
Answer: a) Serialize the object and store it as a
string or binary.
179. What happens if the IDistributedCache SetAsync()
method is called and an item with the same key already exists in the cache?
a) The existing item is updated with the new value.
b) An exception is thrown.
c) The item is left unchanged.
d) The new value is ignored, and the previous value remains unchanged.
Answer: a) The existing item is updated with the new
value.
180. Which of the following cache expiration strategies
is used to remove cache entries when they stop being accessed in .NET Core?
a) Absolute Expiration
b) Sliding Expiration
c) ExpirationCallback
d) No Expiration
Answer: b) Sliding Expiration
183. Which of the following cache strategies ensures that
cache data is not evicted based on usage but is removed after a specific
duration?
a) Sliding Expiration
b) Absolute Expiration
c) Least Recently Used (LRU)
d) FIFO Expiration
Answer: b) Absolute Expiration
184. What does the LRU (Least Recently Used) eviction
strategy do in distributed caching like Redis in .NET Core?
a) Evicts the cache entry with the smallest size.
b) Evicts the cache entry that has been accessed the most.
c) Evicts the cache entry that was used least recently.
d) Evicts the cache entry based on the maximum memory usage.
Answer: c) Evicts the cache entry that was used
least recently.
185. In .NET Core, what is the most efficient approach to
store and retrieve cache data from IDistributedCache in case of frequent access
to the same data?
a) Using a distributed file system cache.
b) Using a SlidingExpiration strategy.
c) Using AbsoluteExpiration for fast retrieval.
d) Storing data without expiration and relying on manual invalidation.
Answer: b) Using a SlidingExpiration strategy.
186. Which method is used to remove a cache entry from
IDistributedCache in .NET Core?
a) DeleteAsync()
b) RemoveAsync()
c) EvictAsync()
d) ClearAsync()
Answer: b) RemoveAsync()
187. Which caching implementation in .NET Core ensures
that all application instances share a common cache, even in a load-balanced
environment?
a) In-memory cache
b) SQL Server cache
c) Redis cache
d) File-based cache
Answer: c) Redis cache
188. Which feature in Redis allows for data persistence
by writing a snapshot of the data to disk at regular intervals?
a) Redis Replication
b) Redis Persistence (RDB snapshots)
c) Redis Eviction
d) Redis Memory Management
Answer: b) Redis Persistence (RDB snapshots)
189. Which of the following is the primary benefit of
using IDistributedCache in a web application?
a) It ensures that cached data is stored in local
memory for better performance.
b) It allows for shared caching across different application
instances.
c) It prevents caching of sensitive data for security reasons.
d) It automatically evicts stale data without configuration.
Answer: b) It allows for shared caching across
different application instances.
191. What happens to a cache entry when Redis eviction
policy is set to volatile-lru?
a) It evicts entries with set expiration times using
LRU strategy.
b) It evicts the oldest entries first.
c) It evicts the least frequently accessed entries.
d) It does not evict any entries.
Answer: a) It evicts entries with set
expiration times using LRU strategy.
192. What is the correct order of operations when
interacting with a distributed cache like Redis in .NET Core?
a) Add -> Retrieve -> Remove
b) Retrieve -> Add -> Update
c) Retrieve -> Add -> Remove
d) Add -> Update -> Retrieve
Answer: a) Add -> Retrieve -> Remove
193. Which of the following cache strategies is the best
for items that frequently change and need to be cached temporarily?
a) Absolute Expiration
b) Sliding Expiration
c) No Expiration
d) Manual Expiration
Answer: b) Sliding Expiration
194. Which of the following methods is used to configure
the memory cache options in IMemoryCache in .NET Core?
a) MemoryCacheOptions
b) CacheConfiguration
c) CacheOptions
d) MemoryCacheSettings
Answer: a) MemoryCacheOptions
195. Which caching approach is generally not recommended
for storing large files such as images or videos in a web application?
a) In-memory caching
b) Redis distributed caching
c) File system caching
d) SQL Server caching
Answer: a) In-memory caching
196. Which of the following is a potential downside of
relying on a distributed cache like Redis in a cloud environment?
a) Limited cache size
b) Reduced cache consistency
c) Increased latency due to network round-trips
d) Lack of support for high availability
Answer: c) Increased latency due to network
round-trips
197. What is the typical timeout for cache entries in
Redis when no expiration time is set?
a) 1 hour
b) 24 hours
c) Indefinitely, unless manually evicted
d) 5 minutes
Answer: c) Indefinitely, unless manually evicted
198. Which of the following cache eviction policies
ensures that Redis will not evict data, even when memory usage exceeds the
configured limits?
a) noeviction
b) volatile-lru
c) allkeys-lru
d) volatile-ttl
Answer: a) noeviction
199. Which of the following Redis features helps to
optimize memory usage when caching large datasets by evicting items as needed?
a) Redis Memory Optimization
b) Redis Maxmemory Policy
c) Redis Compression
d) Redis Expiry Events
Answer: b) Redis Maxmemory Policy
200. In .NET Core, which class can be used to set cache
options like absolute expiration and sliding expiration for cache entries?
a) CacheEntryOptions
b) MemoryCacheOptions
c) CacheItemOptions
d) DistributedCacheOptions
Answer: a) CacheEntryOptions
201. Which of the following statements about distributed
caching in .NET Core is true?
a) Distributed caching improves performance by keeping all
cached data in the local memory of a single instance.
b) Distributed caching is required only for single-instance applications.
c) Distributed caching ensures that cached data is shared across multiple
application instances.
d) Distributed caching reduces the need for application-level cache eviction
strategies.
Answer: c) Distributed caching ensures that cached
data is shared across multiple application instances.
202. What is the primary advantage of using Redis as a
distributed cache compared to SQL Server-based caching?
a) Redis offers better persistence capabilities
than SQL Server.
b) Redis supports automatic scaling without complex
configuration.
c) Redis is faster for caching operations due to its in-memory
design.
d) Redis is more secure than SQL Server for caching sensitive
data.
Answer: c) Redis is faster for
caching operations due to its in-memory design.
203. What method would you use in Redis to store large
binary data (e.g., files) in a cache using .NET Core?
a) SetString()
b) SetBytes()
c) Set()
d) AddFile()
Answer: c) Set()
204. Which of the following is the default cache
expiration behavior in Redis?
a) Items never expire unless explicitly configured.
b) Items expire after 1 minute by default.
c) Items expire after 24 hours by default.
d) Items are removed from the cache immediately after being accessed.
Answer: a) Items never expire unless explicitly
configured.
205. Which method in the IMemoryCache interface allows
you to add or retrieve an item from the cache at the same time, creating it if
it does not exist?
a) GetOrCreate()
b) SetOrCreate()
c) AddOrUpdate()
d) CreateCacheItem()
Answer: a) GetOrCreate()
206. Which of the following methods will invalidate an
entry in the cache if it has expired in IMemoryCache?
a) Invalidate()
b) Remove()
c) Refresh()
d) Evict()
Answer: b) Remove()
207. Which of the following distributed caching
strategies helps in avoiding multiple concurrent calls to the cache when the
data is missing?
a) Cache Aside
b) Write-Through
c) Read-Through
d) Lazy Loading
Answer: a) Cache Aside
208. Which of the following is true about the
IDistributedCache interface in .NET Core?
a) IDistributedCache is only used for reading from
the cache.
b) IDistributedCache provides a thread-safe, simple API for adding, retrieving,
and removing cached data.
c) IDistributedCache is designed only for local in-memory caching.
d) IDistributedCache requires manual cache eviction after a predefined timeout.
Answer: b) IDistributedCache provides a thread-safe,
simple API for adding, retrieving, and removing cached data.
209. Which of the following best describes the concept of
"Cache Invalidation"?
a) Cache Invalidation is the process of adding new
cache entries when required.
b) Cache Invalidation is the manual removal of cache entries
before their expiration.
c) Cache Invalidation ensures that stale data is never cached.
d) Cache Invalidation is used for compressing cache data.
Answer: b) Cache Invalidation is the manual
removal of cache entries before their expiration.
211. What is the default cache size limit in MemoryCache
in .NET Core?
a) 1 MB
b) 2 GB
c) 100 MB
d) There is no default limit unless configured.
Answer: d) There is no default limit unless
configured.
212. Which Redis feature allows for data replication
across multiple Redis servers to enhance fault tolerance?
a) Redis Sharding
b) Redis Clustering
c) Redis Replication
d) Redis Persistence
Answer: c) Redis Replication
213. Which of the following scenarios is most appropriate
for using distributed caching?
a) An application that stores user-specific settings for a
session.
b) An application that caches data to be shared across multiple application
servers.
c) A web application that performs file-based caching on a single server.
d) An application that needs to cache data that does not change often and can
be stored locally.
Answer: b) An application that caches data to be
shared across multiple application servers.
214. Which of the following operations will not cause
cache expiration in Redis?
a) EXPIRE command
b) SET command with an expiration time
c) Adding a new cache entry using the SETNX command
d) Accessing an existing cache entry
Answer: d) Accessing an existing cache entry
215. Which cache-related approach in Redis would help in
avoiding unnecessary data processing on cache misses by automatically loading
missing data into the cache?
a) Cache-Aside
b) Read-Through
c) Write-Through
d) Lazy Loading
Answer: b) Read-Through
216. Which method in IMemoryCache allows you to set
custom cache item options like expiration and priority for a cached item?
a) Set()
b) Create()
c) Add()
d) SetCacheItem()
Answer: a) Set()
217. Which of the following features in Redis helps in
ensuring data persistence by saving the dataset to a disk at specific
intervals?
a) Redis AOF (Append-Only File)
b) Redis Replication
c) Redis Pub/Sub
d) Redis Redisearch
Answer: a) Redis AOF (Append-Only File)
218. In a multi-tier architecture where each tier needs
access to the same cached data, which type of cache is most appropriate?
a) Local in-memory cache
b) Distributed cache
c) File-based cache
d) None of the above
Answer: b) Distributed cache
219. Which of the following strategies is best suited for
a scenario where cached data should only be evicted after a fixed time period,
regardless of its usage?
a) Sliding Expiration
b) Absolute Expiration
c) No Expiration
d) Volatile-LRU
Answer: b) Absolute Expiration
220. In .NET Core, which of the following cache
strategies is best suited for shared data that frequently changes?
a) Absolute Expiration
b) Sliding Expiration
c) Read-Through Caching
d) Cache-Aside Pattern
Answer: b) Sliding Expiration
221. What method in IMemoryCache allows you to remove a
cache entry explicitly by its key?
a) Invalidate()
b) Clear()
c) Remove()
d) Delete()
Answer: c) Remove()
222. In Redis, which command is used to set a cache entry
with an expiration time?
a) SETEX
b) SET
c) PSETEX
d) EXPIRE
Answer: a) SETEX
223. Which of the following scenarios would not benefit
from using caching?
a) Frequently accessed user data in a web application
b) Data that is accessed once and then never needed again
c) Web pages that do not change frequently
d) Computed results that require expensive calculations
Answer: b) Data that is accessed once and then never
needed again
224. What is the purpose of the SlidingExpiration cache
policy in Redis?
a) Cache entries will expire after a fixed amount of
time from when they were added.
b) Cache entries will expire after a fixed amount of time since
the last access or update.
c) Cache entries will never expire unless manually invalidated.
d) Cache entries will be evicted immediately after their first
access.
Answer: b) Cache entries will expire after a fixed
amount of time since the last access or update.
225. In .NET Core, which caching mechanism supports both
local and distributed caches out-of-the-box?
a) Redis
b) IMemoryCache
c) IDistributedCache
d) MemoryCache
Answer: c) IDistributedCache
226. In a Redis-based distributed caching scenario, which
of the following is true about cache persistence?
a) Redis automatically persists all cached data to disk by
default.
b) Redis requires explicit configuration to persist data to disk.
c) Redis does not support persistence and relies only on memory.
d) Redis persists data automatically but only on application shutdown.
Answer: b) Redis requires explicit configuration to
persist data to disk.
227. Which of the following is an advantage of using
MemoryCache in .NET Core for caching over DistributedCache?
a) MemoryCache supports sharing data across
different servers in a distributed system.
b) MemoryCache provides a faster, in-memory cache that is
local to the server.
c) MemoryCache automatically handles cache eviction policies.
d) MemoryCache requires a more complex setup for integration with distributed
systems.
Answer: b) MemoryCache provides a faster,
in-memory cache that is local to the server.
228. What happens when an expired cache entry is accessed
in Redis?
a) The expired entry is returned with a warning message.
b) Redis automatically removes the expired entry and returns
null.
c) Redis continues to return the expired entry but marks it as expired.
d) Redis stores expired entries in a separate expired cache list for later
retrieval.
Answer: b) Redis automatically removes the
expired entry and returns null.
229. In the context of caching, what does "cache
hit" mean?
a) The requested item is found in the cache.
b) The requested item is not found in the cache.
c) The cache is being invalidated or cleared.
d) The cache entry is evicted because of memory constraints.
Answer: a) The requested item is found in the cache.
230. Which of the following Redis commands helps to
persist the data that is currently stored in memory to disk?
a) SAVE
b) BGSAVE
c) FLUSHDB
d) SYNC
Answer: b) BGSAVE
231. In .NET Core, which method is used to check if a
specific key exists in IMemoryCache before attempting to retrieve it?
a) ContainsKey()
b) Exists()
c) KeyExists()
d) TryGetValue()
Answer: d) TryGetValue()
232. Which of the following approaches can help ensure
reliable cache access in the event that a cache server goes down in a
distributed system?
a) Using the Least Recently Used (LRU)
eviction policy
b) Implementing cache replication or fallback to a secondary
cache
c) Using the absolute expiration strategy for all cache
entries
d) Setting the maximum size of the cache in the configuration
Answer: b) Implementing cache replication or
fallback to a secondary cache
234. In a multi-server application with shared cache
needs, which of the following is the most appropriate caching solution?
a) Using an in-memory cache that stores data on each server
individually.
b) Using a distributed cache like Redis or SQL Server to share
cache data across all instances.
c) Using the local file system to store cache entries for each
server instance.
d) Using client-side caching to store data in the user's
browser.
Answer: b) Using a distributed cache like
Redis or SQL Server to share cache data across all instances.
235. Which Redis feature helps in automatic scaling of
cache storage by sharding data across multiple Redis servers?
a) Redis Replication
b) Redis Clustering
c) Redis AOF
d) Redis Persistence
Answer: b) Redis Clustering
236. Which of the following statements is true about
cache invalidation in distributed caching?
a) Cache invalidation only happens on the client-side in
distributed systems.
b) Distributed caches like Redis automatically handle cache invalidation
without the need for manual intervention.
c) Cache invalidation requires manual configuration and may be slow in
distributed systems.
d) Cache invalidation is not necessary when using in-memory caching.
Answer: c) Cache invalidation requires manual
configuration and may be slow in distributed systems.
237. Which of the following is not a common use case for
caching in .NET Core?
a) Storing frequent query results from a
database to avoid repetitive calculations.
b) Caching user-specific data (e.g., preferences, session
data) to reduce load.
c) Storing the entire database in memory for faster access.
d) Caching static assets (e.g., images, stylesheets) for web
performance improvements.
Answer: c) Storing the entire database in
memory for faster access.
238. Which of the following best practices should be used
when setting cache expiration for dynamic, frequently changing data?
a) Set absolute expiration to ensure data
is always evicted after a fixed time.
b) Use sliding expiration to keep the data fresh as long as it
is accessed frequently.
c) Set no expiration to ensure the data never expires.
d) Use manual invalidation for all cache entries.
Answer: b) Use sliding expiration to
keep the data fresh as long as it is accessed frequently.
239. Which method would you use to store a cache entry in
Redis with binary data (such as an image) using .NET Core?
a) SetString()
b) Set()
c) SetBytes()
d) SetBinary()
Answer: b) Set()
240. In Redis, what happens when a cache key is accessed
after it has expired?
a) Redis returns a stale value but marks it
as expired.
b) Redis automatically removes the expired key and returns
null.
c) Redis will continue returning the expired value until
explicitly deleted.
d) Redis will raise an error indicating the key is expired.
Answer: b) Redis automatically removes the
expired key and returns null.
241. Which of the following caching strategies is used
when you want to cache the data only after it is fetched from a data source,
and avoid loading the data multiple times in parallel?
a) Cache-Aside
b) Read-Through
c) Write-Through
d) Lazy Loading
Answer: a) Cache-Aside
242. Which of the following commands is used in Redis to
remove all keys from the current database?
a) FLUSHDB
b) DELETE
c) REMOVE
d) FLUSHALL
Answer: a) FLUSHDB
243. In .NET Core, which class allows you to implement
expiration policies, such as absolute or sliding expiration for cache entries?
a) MemoryCache
b) CacheItemPolicy
c) CacheEntryOptions
d) CacheContext
Answer: c) CacheEntryOptions
245. What is the primary goal of a cache aside caching
pattern?
a) To keep the cache synchronized with the
underlying data store.
b) To automatically load data from the cache when needed without custom logic.
c) To manually add data to the cache from a data store when the data is first
requested.
d) To ensure cache data never expires without manual
intervention.
Answer: c) To manually add data to the cache from a
data store when the data is first requested.
246. Which of the following options is true about
IDistributedCache in .NET Core?
a) It can be used only with SQL Server for
distributed caching.
b) It requires the use of Redis for distributed caching.
c) It abstracts different distributed caching mechanisms (like Redis, SQL
Server, NCache).
d) It is designed only for in-memory caching in a single
instance application.
Answer: c) It abstracts different distributed caching
mechanisms (like Redis, SQL Server, NCache).
247. In .NET Core, which of the following methods in
IMemoryCache allows conditional removal of a cache entry?
a) Remove()
b) RemoveIfExpired()
c) TryRemove()
d) RemoveByKey()
Answer: a) Remove()
248. What is the purpose of EXPIRE command in Redis?
a) To delete a cache key from the Redis cache immediately.
b) To set a time-to-live (TTL) for a specific cache key.
c) To reset the TTL of a cache key to its default value.
d) To add a new key-value pair to the cache if the key does not already exist.
Answer: b) To set a time-to-live (TTL) for
a specific cache key.
249. Which of the following scenarios is most suitable
for using absolute expiration in a caching strategy?
a) A cache entry should expire after a specific
fixed amount of time regardless of its usage.
b) A cache entry should expire after being idle for a set period.
c) A cache entry should be refreshed after every access.
d) A cache entry should never expire, only invalidate when manually removed.
Answer: a) A cache entry should expire after a specific
fixed amount of time regardless of its usage.
250. Which method in the IDistributedCache interface
allows you to store cache data with absolute expiration in Redis or other
distributed caches?
a) Set()
b) SetAsync()
c) SetItem()
d) SetWithExpiration()
Answer: b) SetAsync()
251. What happens when a cache entry in Redis reaches its
expiration time?
a) It remains in memory but is marked as expired until
explicitly deleted.
b) Redis automatically removes the expired entry from memory.
c) It gets persisted to disk for future retrieval.
d) It triggers a background cleanup process to delete expired
entries periodically.
Answer: b) Redis automatically removes the
expired entry from memory.
252. Which of the following approaches helps to prevent
cache stampede (multiple requests fetching the same data when cache misses
occur)?
a) Using sliding expiration for cache
entries.
b) Using synchronization mechanisms to lock the cache and
prevent duplicate requests.
c) Using absolute expiration for cache entries.
d) Allowing requests to wait until the cache is updated from the data source.
Answer: b) Using synchronization mechanisms
to lock the cache and prevent duplicate requests.
253. What is the default behavior for cache invalidation
when a cache entry is updated in Redis?
a) The cache entry is updated without any expiration set.
b) The cache entry is automatically removed when an update
occurs.
c) The cache entry is overwritten, and the TTL is reset if
configured.
d) The cache entry expires immediately after being updated.
Answer: c) The cache entry is overwritten,
and the TTL is reset if configured.
254. Which of the following strategies would be most
suitable for caching frequently accessed but rarely changing data?
a) Write-Through
b) Cache-Aside
c) Read-Through
d) Lazy Loading
Answer: b) Cache-Aside
255. Which Redis data type is not suitable for caching
dynamic or frequently changing data?
a) String
b) List
c) Hash
d) Set
Answer: b) List
256. Which method in IMemoryCache should be used to store
a cache entry with custom expiration policy and priority?
a) Set()
b) Add()
c) Insert()
d) AddWithOptions()
Answer: a) Set()
257. Which caching mechanism in .NET Core can be used to
manage cache keys and values across multiple instances of an application?
a) IMemoryCache
b) IDistributedCache
c) MemoryCache
d) LocalCache
Answer: b) IDistributedCache
258. What is the benefit of using cache warm-up
strategies in distributed systems?
a) It improves system scalability by
distributing cache load across servers.
b) It pre-fills the cache with commonly requested data during
startup to avoid cache misses.
c) It automatically updates the cache whenever the data
changes.
d) It ensures cache persistence across multiple servers and
nodes.
Answer: b) It pre-fills the cache with
commonly requested data during startup to avoid cache misses.
259. In Redis, which of the following commands will set a
key only if the key does not already exist?
a) SET
b) SETNX
c) GETNX
d) SETIFNOTEXISTS
Answer: b) SETNX
260. Which of the following .NET Core components should
you use for distributed caching when scaling out an application across multiple
servers?
a) MemoryCache
b) IDistributedCache
c) CacheEntry
d) DistributedMemoryCache
Answer: b) IDistributedCache
These additional questions will further test your
understanding of caching patterns, strategies, Redis commands, and memory
management in .NET Core.
Here are more Cache in .NET Core MCQs:
261. Which of the following caching strategies helps
avoid caching duplicate data during high traffic spikes?
a) Cache-Aside
b) Write-Through
c) Lazy Loading
d) Cache Invalidation
Answer: c) Lazy Loading
262. Which method in IMemoryCache can be used to retrieve
a cache entry without adding it if it doesn’t exist?
a) Get()
b) TryGetValue()
c) GetOrAdd()
d) Set()
Answer: b) TryGetValue()
263. In Redis, which data type would be the most
efficient for storing key-value pairs?
a) String
b) List
c) Set
d) Hash
Answer: a) String
264. What is the primary reason for using distributed
caching in a web application?
a) To store cache entries in local memory across
all application instances.
b) To share cache data across multiple servers or instances in
a distributed system.
c) To handle cache invalidation automatically.
d) To ensure that cache entries can be accessed offline.
Answer: b) To share cache data across
multiple servers or instances in a distributed system.
265. Which of the following is a common eviction strategy
used by Redis to free up space when memory usage exceeds the limit?
a) volatile-random
b) allkeys-lru
c) volatile-ttl
d) noeviction
Answer: b) allkeys-lru
266. Which of the following methods is used to add or
replace a cache entry in Redis, but only if the cache entry doesn’t already
exist?
a) SET
b) SETNX
c) GETSET
d) MSET
Answer: b) SETNX
267. Which of the following methods in IMemoryCache
allows you to retrieve and update an existing cache entry?
a) TryGetValue()
b) Set()
c) GetOrAdd()
d) Update()
Answer: c) GetOrAdd()
268. Which of the following is the primary benefit of
using DistributedMemoryCache in a multi-instance .NET Core application?
a) It reduces network traffic by serving
the same cache from all instances.
b) It ensures that cache entries are shared across multiple
instances of the application.
c) It allows local caching on each instance for performance.
d) It automatically invalidates cache entries after a fixed
period.
Answer: b) It ensures that cache entries are shared across
multiple instances of the application.
269. Which of the following commands can be used to
persist a Redis cache entry to disk, while Redis is running?
a) SAVE
b) BGSAVE
c) FLUSHDB
d) SYNC
Answer: b) BGSAVE
270. In a distributed cache setup, what does cache
synchronization mean?
a) Synchronizing cache to ensure data
consistency across multiple instances.
b) Keeping cache entries in sync with a centralized data store.
c) Automatically synchronizing cache entries between local and
distributed caches.
d) Using replication to ensure cache data is updated
immediately.
Answer: a) Synchronizing cache to
ensure data consistency across multiple instances.
271. Which of the following strategies is best suited for
caching frequently read, rarely updated data?
a) Cache-Aside
b) Write-Through
c) Read-Through
d) Lazy Loading
Answer: a) Cache-Aside
272. Which of the following Redis commands is used to
remove a cache entry from Redis by its key?
a) DELETE
b) REMOVE
c) UNLINK
d) DEL
Answer: d) DEL
273. What caching strategy should be used when data needs
to be loaded automatically into the cache upon request?
a) Cache-Aside
b) Write-Through
c) Read-Through
d) Lazy Loading
Answer: c) Read-Through
274. What happens when a cache entry in Redis is updated
after its expiration time?
a) Redis ignores the update if the entry is expired.
b) Redis updates the entry without resetting the TTL.
c) Redis deletes the expired entry and sets a new entry with
the updated value.
d) Redis refreshes the cache TTL with every update.
Answer: d) Redis refreshes the cache
TTL with every update.
275. Which of the following is not a valid method to
expire cache entries in Redis?
a) EXPIRE
b) EXPIREAT
c) SETEX
d) EVICT
Answer: d) EVICT
276. Which of the following Redis features allows you to
partition data into smaller subsets across multiple Redis instances?
a) Redis Clustering
b) Redis Persistence
c) Redis Replication
d) Redis AOF (Append-Only File)
Answer: a) Redis Clustering
277. What does SlidingExpiration mean in cache policies?
a) The cache entry expires after a fixed
period of time.
b) The cache entry expires after a fixed time since the last
access.
c) The cache entry is never expired unless manually removed.
d) The cache entry is refreshed with each access.
Answer: b) The cache entry expires after
a fixed time since the last access.
278. Which of the following can help in preventing cache
stampede by handling high traffic at the same time?
a) Using a read-through cache pattern.
b) Caching only frequently accessed data.
c) Using synchronization to allow only one request to fetch
data.
d) Enabling sliding expiration for cache entries.
Answer: c) Using synchronization to
allow only one request to fetch data.
279. In Redis, what does the command PERSIST do to a key
with an expiration set?
a) It removes the expiration, keeping the key
indefinitely.
b) It extends the expiration time by a specified duration.
c) It removes the key from the cache.
d) It sets a new expiration time on the key.
Answer: a) It removes the expiration,
keeping the key indefinitely.
280. Which of the following caching strategies ensures
that cache entries are updated immediately after being written to the
underlying data store?
a) Cache-Aside
b) Write-Through
c) Read-Through
d) Lazy Loading
Answer: b) Write-Through
281. Which of the following caching strategies is best
suited for ensuring that the cache always reflects the latest data from the
data store?
a) Cache-Aside
b) Write-Through
c) Read-Through
d) Lazy Loading
Answer: b) Write-Through
Explanation:
282. Which of the following is true when using Redis for
persistent caching?
a) Redis data is stored only in memory and is lost after a
restart.
b) Redis persists data on disk by default for recovery after a restart.
c) Redis supports replication but does not provide data
persistence.
d) Redis does not support persistent storage for cache data.
Answer: b) Redis persists data on disk by default for
recovery after a restart.
Explanation:
283. Which method is used to set a cache entry with an
absolute expiration time using MemoryCache in .NET Core?
a) Set()
b) Add()
c) SetWithAbsoluteExpiration()
d) SetAsync()
Answer: a) Set()
Explanation:
284. Which of the following Redis data types is best
suited for caching a collection of values?
a) String
b) Set
c) Hash
d) List
Answer: b) Set
Explanation:
286. Which of the following .NET Core components provides
distributed caching functionality?
a) MemoryCache
b) IDistributedCache
c) DistributedMemoryCache
d) InMemoryDistributedCache
Answer: b) IDistributedCache
Explanation:
287. What is the purpose of the TTL (Time-to-Live) for
cache entries in Redis?
a) To specify how often the cache entry should be updated.
b) To control how long a cache entry remains in memory before
it expires.
c) To define how long the cache server will wait before evicting data.
d) To guarantee that data in cache is always accessible.
Answer: b) To control how long a cache entry remains
in memory before it expires.
Explanation:
288. Which of the following cache eviction policies
allows Redis to evict expired keys automatically when Redis memory is full?
a) volatile-lru
b) volatile-ttl
c) allkeys-lru
d) noeviction
Answer: a) volatile-lru
Explanation:
289. What is the function of SETEX command in Redis?
a) It sets a cache entry with an expiration time.
b) It sets a cache entry only if it does not already exist.
c) It updates the cache entry without changing expiration.
d) It returns the value of an expired key.
Answer: a) It sets a cache entry with an
expiration time.
Explanation:
290. Which caching strategy would you use if you need to
cache the result of a query, but avoid querying the data store multiple times
at the same time due to cache misses?
a) Cache-Aside
b) Write-Through
c) Lazy Loading
d) Read-Through
Answer: c) Lazy Loading
Explanation:
291. Which of the following Redis commands is used to
retrieve a value by key from Redis?
a) GET
b) GETBYKEY
c) FETCH
d) READ
Answer: a) GET
Explanation:
292. Which .NET Core method can be used to remove a cache
entry from the IMemoryCache?
a) Clear()
b) Remove()
c) Delete()
d) Invalidate()
Answer: b) Remove()
Explanation:
293. Which of the following features is used in Redis to
replicate data between multiple Redis instances for high availability?
a) Redis Cluster
b) Redis Persistence
c) Redis Replication
d) Redis Sentinel
Answer: c) Redis Replication
Explanation:
294. Which method in IDistributedCache is used to store a
cache entry asynchronously?
a) SetAsync()
b) AddAsync()
c) SetEntryAsync()
d) InsertAsync()
Answer: a) SetAsync()
Explanation:
295. In .NET Core, which cache entry expiration strategy
allows the cache entry to expire after a certain fixed period since the cache
entry was created?
a) Absolute Expiration
b) Sliding Expiration
c) Forced Expiration
d) Expiration by Access
Answer: a) Absolute Expiration
Explanation:
297. Which of the following Redis commands sets a cache
entry with an expiration time?
a) SET
b) SETEX
c) EXPIRE
d) SETNX
Answer: b) SETEX
Explanation:
298. Which of the following scenarios is not suitable for
using caching?
a) Frequently accessed data with a high cost to
fetch.
b) Expensive calculations that are reused frequently.
c) Storing highly dynamic data that changes every second.
d) Frequently accessed static data.
Answer: c) Storing highly dynamic data that
changes every second.
Explanation:
299. Which of the following Redis data types is most
suitable for caching a list of items?
a) String
b) List
c) Hash
d) Set
Answer: b) List
Explanation:
300. Which of the following .NET Core caching strategies
ensures that cache entries are updated automatically when a cache miss occurs?
a) Cache-Aside
b) Write-Through
c) Read-Through
d) Lazy Loading
Answer: c) Read-Through
Explanation:
301. Which of the following methods can be used to
configure caching in a distributed .NET Core application using Redis?
a) AddMemoryCache()
b) AddDistributedMemoryCache()
c) AddRedisCache()
d) AddDistributedCache()
Answer: c) AddRedisCache()
Explanation:
302. Which of the following methods is used to remove a
cache entry from the distributed cache in .NET Core?
a) RemoveAsync()
b) ClearAsync()
c) InvalidateAsync()
d) DeleteAsync()
Answer: a) RemoveAsync()
Explanation:
303. What is the primary difference between
IDistributedCache and IMemoryCache in .NET Core?
a) IDistributedCache is used for local memory
caching, while IMemoryCache is used for distributed caching.
b) IMemoryCache stores data in memory, while IDistributedCache
stores data in a distributed system like Redis or SQL Server.
c) IDistributedCache is faster than IMemoryCache.
d) There is no significant difference between IMemoryCache and
IDistributedCache.
Answer: b) IMemoryCache stores data in memory,
while IDistributedCache stores data in a distributed system like
Redis or SQL Server.
Explanation:
304. Which Redis command is used to increment a value
stored in Redis?
a) INCRBY
b) SETINCR
c) ADD
d) INCR
Answer: d) INCR
Explanation:
305. In Redis, which data structure should be used for
storing data in a key-value pair format?
a) List
b) Set
c) Hash
d) String
Answer: d) String
Explanation:
306. What caching mechanism is used when an entry is
loaded into the cache on-demand and not preloaded?
a) Cache-Aside
b) Write-Through
c) Read-Through
d) Lazy Loading
Answer: a) Cache-Aside
Explanation:
307. Which of the following Redis commands would you use
to set a cache entry in Redis with an expiration time?
a) SETEX
b) SET
c) EXPIRE
d) ADD
Answer: a) SETEX
Explanation:
308. What is the role of DistributedCache in a .NET Core
application?
a) To store data locally on the server in memory.
b) To share cache data between multiple application instances across a distributed
environment.
c) To manage in-memory cache entries for a single application.
d) To manage database connections for the application.
Answer: b) To share cache data between multiple
application instances across a distributed environment.
Explanation:
309. Which of the following methods is used to add a
cache entry to IMemoryCache in .NET Core?
a) Add()
b) Set()
c) Store()
d) Put()
Answer: b) Set()
Explanation:
310. Which of the following strategies prevents cache
stampede, where multiple requests try to fetch the same expired cache entry at
once?
a) Write-Through
b) Lazy Loading
c) Read-Through
d) Synchronizing cache updates to avoid multiple requests fetching the same
data simultaneously
Answer: d) Synchronizing cache updates to avoid
multiple requests fetching the same data simultaneously
311. What happens when an entry in IMemoryCache is set
with sliding expiration?
a) The cache entry expires after a fixed
time regardless of access.
b) The cache entry expires based on the last access time and
resets on every access.
c) The cache entry never expires and stays in memory
indefinitely.
d) The cache entry is removed immediately after it's accessed.
Answer: b) The cache entry expires based on the last
access time and resets on every access.
Explanation:
312. What is the maximum size allowed for a cache entry
in IMemoryCache in .NET Core?
a) 1 GB
b) 2 GB
c) 50 MB
d) There is no fixed maximum size; it depends on the available memory.
Answer: d) There is no fixed maximum size; it depends
on the available memory.
Explanation:
314. Which of the following Redis commands is used to set
a timeout on an existing key?
a) EXPIRE
b) SETEX
c) TTL
d) TIMEOUT
Answer: a) EXPIRE
Explanation:
315. What is the default behavior when trying to add a
cache entry to IMemoryCache in .NET Core, but the cache already contains an
entry for the same key?
a) The entry will overwrite the existing
cache entry.
b) The cache entry will be ignored.
c) An exception will be thrown.
d) The existing cache entry will be removed.
Answer: a) The entry will overwrite the
existing cache entry.
Explanation:
317. Which of the following is true about using Redis as
a distributed cache in .NET Core?
a) Redis only works for single-instance applications.
b) Redis provides a persistent cache that can survive
application restarts.
c) Redis does not support expiration or eviction policies.
d) Redis requires manual invalidation of cache entries.
Answer: b) Redis provides a persistent cache that
can survive application restarts.
Explanation:
318. Which of the following methods allows you to store a
cache entry asynchronously in IDistributedCache in .NET Core?
a) SetAsync()
b) AddAsync()
c) StoreAsync()
d) PutAsync()
Answer: a) SetAsync()
Explanation:
320. Which of the following cache patterns allows data to
be fetched from the cache or directly from the data store if the cache miss
occurs?
a) Cache-Aside
b) Read-Through
c) Write-Through
d) Lazy Loading
Answer: a) Cache-Aside
Explanation:
321. Which of the following Redis commands is used to
delete a key in Redis?
a) DEL
b) REMOVE
c) DELETE
d) EXPUNGE
Answer: a) DEL
Explanation:
322. Which of the following is not a valid cache eviction
policy in Redis?
a) volatile-lru
b) volatile-ttl
c) allkeys-random
d) allkeys-lfu
Answer: d) allkeys-lfu
Explanation:
324. In .NET Core, which cache expiration strategy should
be used when the cache entry needs to expire after a fixed period regardless of
access?
a) Sliding Expiration
b) Absolute Expiration
c) Lazy Loading
d) Read-Through
Answer: b) Absolute Expiration
Explanation:
325. What type of cache entry expiration strategy resets
the expiration time every time the cache entry is accessed?
a) Absolute Expiration
b) Sliding Expiration
c) Forced Expiration
d) Expiration by Access
Answer: b) Sliding Expiration
Explanation:
326. Which of the following caching strategies is best
suited for data that is accessed frequently and needs to be cached for long
periods of time?
a) Write-Through
b) Read-Through
c) Cache-Aside
d) Lazy Loading
Answer: c) Cache-Aside
Explanation:
328. In a distributed environment, which of the following
is true when using IDistributedCache for caching?
a) The cache is maintained locally on each server.
b) Cache entries are shared across all servers in the distributed environment.
c) Data is only cached in memory without persistence.
d) The cache is cleared every time the application restarts.
Answer: b) Cache entries are shared across all
servers in the distributed environment.
Explanation:
329. Which of the following is the correct namespace for
using Redis as a distributed cache in .NET Core?
a) Microsoft.Extensions.Caching.Redis
b) Microsoft.Extensions.Caching.Distributed
c) Microsoft.AspNetCore.Caching.Redis
d) Microsoft.AspNetCore.Caching
Answer: a) Microsoft.Extensions.Caching.Redis
Explanation:
330. Which of the following is an important feature of
Redis when used as a distributed cache in .NET Core?
a) Redis can only cache strings.
b) Redis supports data persistence, meaning data can survive Redis
restarts.
c) Redis supports only in-memory caching with no options for
data recovery.
d) Redis does not support replication for high availability.
Answer: b) Redis supports data persistence,
meaning data can survive Redis restarts.
Explanation:
331. In .NET Core, which interface does
DistributedMemoryCache implement?
a) IMemoryCache
b) IDistributedCache
c) IOptionsCache
d) ICacheProvider
Answer: b) IDistributedCache
Explanation:
332. Which of the following Redis data structures is best
suited for storing a collection of unique values with no specific order?
a) String
b) List
c) Set
d) Hash
Answer: c) Set
Explanation:
333. Which of the following Redis commands is used to set
an expiration time for a key, in seconds?
a) EXPIRE
b) TTL
c) SETEX
d) EXPIREAT
Answer: a) EXPIRE
Explanation:
334. What does CACHE MISS mean in the context of caching?
a) The cache entry has expired.
b) The cache entry is not found in the cache, so it needs to
be fetched from the data store.
c) The cache entry was removed manually.
d) The cache entry is not accessible due to a network issue.
Answer: b) The cache entry is not found in
the cache, so it needs to be fetched from the data store.
Explanation:
336. Which method is used to add a cache entry to
IMemoryCache in .NET Core?
a) AddCache()
b) PutCache()
c) Set()
d) Store()
Answer: c) Set()
Explanation:
337. Which of the following is not an advantage of
caching in .NET Core?
a) Reduces latency for frequently accessed data.
b) Reduces load on data stores and databases.
c) Guarantees that data in cache will always be up-to-date.
d) Increases application performance by avoiding redundant computations.
Answer: c) Guarantees that data in cache will always
be up-to-date.
Explanation:
338. Which of the following is true for using in-memory
caching in .NET Core?
a) It allows caching across multiple servers in a
distributed environment.
b) The cached data is only stored in memory on the same server
where the cache is created.
c) It provides persistence for cache entries.
d) It is ideal for highly sensitive data that must be
encrypted.
Answer: b) The cached data is only stored in
memory on the same server where the cache is created.
Explanation:
339. Which of the following methods in IDistributedCache
is used to get a cache entry?
a) Get()
b) Fetch()
c) Retrieve()
d) Read()
Answer: a) Get()
Explanation:
340. Which of the following is true about Write-Through
caching in .NET Core?
a) Data is written to cache only when data
is explicitly requested by the application.
b) Data is written to the cache and the data store simultaneously on
each update.
c) Cache entries are invalidated after a fixed period of time.
d) Cache data is stored in memory only and never in a
persistent data store.
Answer: b) Data is written to the cache and
the data store simultaneously on each update.
Explanation:
342. What does SETNX Redis command do?
a) Sets the value of a key only if the key does not
exist.
b) Sets the value of a key only if the key already exists.
c) Sets the value of a key and adds an expiration.
d) Sets the value of a key and increments the value.
Answer: a) Sets the value of a key only if the
key does not exist.
Explanation:
343. Which of the following is true for caching patterns?
a) Cache-Aside allows for the data store to manage
cache entries automatically.
b) Read-Through updates the cache automatically when data is
updated in the data store.
c) Write-Through caches data on write to prevent cache misses
on subsequent reads.
d) Lazy Loading ensures that the cache is preloaded with data.
Answer: c) Write-Through caches data on write to
prevent cache misses on subsequent reads.
Explanation:
Comments
Post a Comment