Skip to content

Backend Development: Caching

Lee Zhan Peng edited this page Apr 26, 2024 · 1 revision

On this page, we describe our strategy for reducing the load of the application and preventing unnecessary repeated API calls.

Caching in Our Application

Caching Banner

Introduction

Caching plays a crucial role in optimising the performance and efficiency of our application, especially when dealing with frequent API calls (AWS, n.d.). In order to reduce the load on our servers and improve response times, we have implemented a simple caching system.

Purpose of Caching

The primary purpose of caching in our application is to store frequently accessed data temporarily, allowing us to retrieve it quickly without having to recall APIs or database queries. By caching data locally, we can reduce the load on our servers and improve overall system performance.

How Our Caching System Works

Our cache system can be referred to here.

CacheClient Class

We have implemented a simple caching system using the CacheClient class. This class provides methods for storing, retrieving, and managing cached data.

Initialisation

When an instance of the CacheClient class is created, it initialises an empty cache dictionary.

Retrieval

The retrieve method allows us to retrieve data from the cache using a specified key. If the data is found in the cache, it is returned; otherwise, it returns False.

Update

The update method allows us to update the cache with a new key-value pair. This method is typically used to cache data retrieved from API calls.

Reset

The reset method allows us to reset the cache by clearing all stored data. This can be useful for refreshing the cache or clearing outdated data.

Key Generation

The generate_key method generates a cache key based on the type of data being cached and any additional arguments provided. This ensures that each piece of data is uniquely identified in the cache.

Conclusion

Our simple caching system effectively reduces the load on our servers by caching frequently accessed data locally. By storing data temporarily in memory, we can significantly improve response times and enhance the overall performance of our application.

References

Amazon Web Services. (n.d.). Caching Overview.