Table of contents
1.
Introduction
2.
Job Caching
3.
Default Job Cache
3.1.
Reducing the Size of the Default Job Cache
4.
Frequently Asked Questions
4.1.
What are the advantages of using the master job cache?
4.2.
What is the main advantage of using the external job cache?
4.3.
Where can I find the default job cache directory in Salt?
5.
Conclusion
Last Updated: Mar 27, 2024

Job Cache In Salt

Author Lokesh Sharma
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Hi Ninja, Welcome to another exciting blog by coding ninjas. We hope you are doing fine. This article will tell you about the caching of jobs in salt. We will learn about the default job cache and how it works. 

job cache in salt

Job Caching

Salt works on a client-server model. The Salt master is responsible for the execution of a large number of jobs. The servers, known as minions, execute these jobs and return the data to the master. The master may need to access any particular job data from a large pool of data resources. However, searching for a specific job result and querying it consumes a lot of time. 

We can create a cache to avoid the problem mentioned above. With caching of job results, searching and querying become faster. We call this cache the default job cache.

Default Job Cache

As the name suggests, this cache is salt’s default for storing job data. It uses Salt master’s local storage to store and cache data which we can find inside the job cache directory. This system is the simplest caching system as it does not require further management or configuration. This feature makes the default caching system very suitable for deployments. 

By default, the jobs stored in this cache will get erased after 24 hours. However, it allows us to change this buffer time to a different period. We can do so by setting the keep_jobs parameter to a different value. We can find this option inside the master’s configuration file. This parameter accepts the value in hours.

For example, if we want the jobs cached for two days, then we can write the following code:

keep_jobs: 48.

Reducing the Size of the Default Job Cache

We know that every cache consumes memory. The Default Job Cache may create overhead and system lag if it caches a large number of minions (greater than 5000). A simple solution to this problem is to disable the job cache. Disabling the cache will lead to the unavailability of job data. 

However, this approach is not recommended. If we remove the cache, the master will take a lot of time to access the desired results. It is always better to have a fast input-output system. 

Nevertheless, you can avoid caching of data by setting the job_cache parameter to False. Now, the master will not create a cache but a JID directory. This directory will store a jid file for each job. So if you want to reduce the burden on the Salt master, you can set the job_cache to False and change the keep_jobs option to a lower value, such as 1.

Note that while lowering the value of the keep_jobs options, you should always keep it above zero. A zero value of this option means the cache will never get empty. 

As we discussed above, storing a large amount of data on local storage is inefficient. So many deployments use external storage to cache data. This method allows them to keep the results of executed jobs for extended periods. Salt provides mainly two types of external storage, the master job cache and the external job cache. 

The external job cache returns the data directly from the minions. At the same time, the master job cache returns data from the master. 

Frequently Asked Questions

What are the advantages of using the master job cache?

Master job cache is a type of external cache system of salt. The main benefit of using this system is that only a single connection is required. We prefer it for databases and similar systems. 

What is the main advantage of using the external job cache?

The main advantage of using the external salt cache is that data is stored directly from the minions. This method decreases the load on the Salt master.

Where can I find the default job cache directory in Salt?

You can find the default job cache directory in the jobs folder inside the master directory, var->cache->salt->master->jobs.

Conclusion

In this article, we discussed the Cache management system in Salt. We discussed job caching, the default job cache, and how to manipulate it. We also learned about reducing the size of the job cache.

We sincerely hope the above discussion helped you understand Cache management in Salt. You can refer to our blogs on job management and access control if you wish to learn more about Salt. 

Visit our website to read more such blogs. Make sure you enroll in our other courses as well. You can take mock testssolve problems, and interview puzzles. Also, you can check out some exciting interview stuff- interview experiences and an interview bundle for placement preparations. Do upvote our blog to help fellow ninjas grow.

Keep Grinding! 🦾

Happy Coding! 💻

Live masterclass