Article

Software Development

Zoho

Making Your Node.js Apps Faster with Zoho Catalyst Cache

Posted on April 19, 2024

By Mike Dranginis

May 25, 2024

Making Your Node.js Apps Faster with Zoho Catalyst Cache 

In today’s fast-paced digital world, developers and stakeholders paying these developers to bring their applications to life want their systems to run smoothly and quickly. This is where Zoho Catalyst Cache comes into play, especially for apps built with Node.js. Catalyst Cache offers a robust mechanism for data caching, storing data in a way that makes it quicker to access.  

In this article, we’ll dive into what Zoho Catalyst Cache is all about and how you can use it to speed up your Node.js applications. We’ll walk you through setting up two examples: one without caching and another with the power of Zoho Catalyst Cache, so you can see the difference it makes. 

Your Guide to Zoho Catalyst Cache 

What is Zoho Catalyst Cache? 

Imagine a super-fast storage space where your app can quickly access the data it uses all the time. That’s what Zoho Catalyst Cache is all about. It’s a special tool designed to make apps run smoother and faster by smartly storing and fetching your most accessed data. This tool is part of Zoho’s cloud services. 

Why is Catalyst Cache so fast? Because it uses memory caching, keeping your data ready to go in a super-quick storage area, cutting down the wait time and making your app feel faster to users. Plus, it’s built on a system called Redis cache, backed by Zoho’s strong tech setup. 

Key Features: 

  • Memory Caching: Think of this as keeping your most-used apps right on your phone’s home screen for quick access. Zoho Catalyst Cache does this for your app’s data. 
  • Distributed Architecture: This ensures that as your app grows and more users come on board, the system can handle it smoothly without any hiccups.
  • Data Consistency: This feature keeps your data accurate and consistent across the cache. 
  • Flexible Configuration: Every app is unique, and this feature lets you customize how data is cached to best suit your app’s needs. 

Understanding Zoho Catalyst Cache: Simplified 

To make Zoho Catalyst Cache a bit easier to understand, let’s break down the two main parts you’ll work with: segments & cache items 

Think of segments as separate rooms in a house, each dedicated to a specific type of activity or purpose. In Zoho Catalyst Cache, segments help you keep your data neatly organized. When you set up a segment, Zoho gives it a unique ID so you can find and manage it easily, either through a control panel or directly in your app. 

Inside each room (segment), you have cache items. In Zoho Catalyst Cache, each item is a pair: a name (key) and its content (value). Plus, each item has a “shelf life” (expiration time) showing how long it’s useful for, usually set for two days. But if you need, you can change this to any time up to two days, making sure your data is as fresh as you need it to be. 

Why is this important? Imagine you’re running an app that shows sales data, with lots of numbers and charts updated daily, weekly, or monthly. Calculating all this on the fly for every user can slow things down, making your app feel sluggish and possibly even causing it to time out. By using segments, you can store each type of data or dashboard in its own “room,” making sure everything is where it should be. Then, with cache items, you keep the most current version ready to go. This way, everyone gets the speedy, smooth experience they want, without waiting for those calculations every time. 

Boosting Efficiency Across Industries 

Zoho Catalyst Cache is a versatile tool that enhances the performance and scalability of various types of applications. Here’s how it’s making a difference in several key areas: 

  • E-Commerce Platforms: By caching product information, e-commerce sites can handle spikes in visitor numbers without overloading their databases. This means that even during big sales or holiday rushes, customers experience quick loading times for product pages, leading to a smoother shopping experience. 
  • Social Media Networks: Social media apps use caching to keep user timelines and posts ready to display, ensuring that users can scroll through updates without any annoying delays. This is crucial for keeping the platform engaging and responsive, especially when handling millions of active users. 
  • Financial Services: Financial applications cache essential market data to provide quick access to portfolio analyses and real-time market trends. This allows users to make informed decisions faster, a critical advantage in the fast-paced world of finance. 
  • Media Outlets: News platforms cache articles and media content to deliver news stories and videos quickly, regardless of the surge in readership. This ensures that the latest news is always accessible without waiting, enhancing user satisfaction and engagement. 
  • Educational Platforms: Educational apps cache course materials and video content, enabling instant access for learners. This is especially important for supporting a smooth learning experience, even during peak access times when many students are logging in to study. 
  • Health and Fitness Apps: By caching individual user progress and health metrics, fitness apps can offer personalized recommendations and track achievements without delays, encouraging continued user engagement and motivation. 

In each of these scenarios, Zoho Catalyst Cache plays a pivotal role in ensuring applications are scalable, resilient, and capable of providing a high-quality user experience. By effectively managing how data is stored and accessed, it helps businesses across sectors keep pace with user expectations and technological advancements. 

Want to learn more? Book a meeting with us today!

Real-World Use Case 

Let’s go back to the example of caching for sales and create a simplified version of what a cache would look like.  

First, access your Zoho account and open the Catalyst dashboard. From there, you can create your own Catalyst project.  

Screenshot of a "create project" interface with fields for entering a project name and informational note, and buttons for "cancel" and "create".

Next, you will be redirected to the following view. 

Screenshot of a desktop interface showing a data storage management application with options on the left sidebar and a central graphic of a storage container.

Create a new segment and name it something like “Sales” 

A user interface screen titled "create segment" with fields for "segment name" filled with "users," and buttons labeled "cancel" and "create.

Next, write the following command in the terminal to initialize the Catalyst project in the directory of your choice. 

Screenshot of a computer terminal with a prompt for selecting a default catalyst project for a directory, showing options to create or import a project.

Then check the function 

Screenshot of a computer screen showing a terminal interface with options for a catalyst project setup, highlighted on option "c: aspili: configure and deploy aspili services.

Finally, select AdvancedIO.

A computer terminal screen displaying options for setting up functions in a directory, with types listed as "event," "cron," and "browser logic.

Paste the following code in your index.js file. 

 

const express = require("express"); 

const app = express(); 

const catalyst = require("zcatalyst-sdk-node"); 

 

// Mock function to simulate fetching total sales for a specific day from the database 

async function fetchTotalSalesFromDatabase(day) { 

 console.log(`Fetching total sales for ${day} from the database...`); 

 // Simulated delay to mimic database query time 

 await new Promise((resolve) => setTimeout(resolve, 1000)); 

 return Math.floor(Math.random() * 1000); 

} 

 

// Mock function to simulate fetching returns for a specific day from the database 

async function fetchReturnsFromDatabase(day) { 

 console.log(`Fetching returns for ${day} from the database...`); 

 // Simulated database query 

 return Math.floor(Math.random() * 100); 

} 

 

// Function to calculate total daily sales minus returns, with caching 

async function calculateNetSalesForDay(segment, day) { 

 // Attempt to fetch net sales from the cache 

 const cachedNetSales = await segment.get(day); 

 

 if (cachedNetSales.cache_value) { 

   console.log(`Fetching net sales for ${day} from the cache...`); 

   return cachedNetSales; 

 } 

 

 // If not found in cache, calculate net sales by fetching total sales and returns 

 const totalSales = await fetchTotalSalesFromDatabase(day); 

 const returns = await fetchReturnsFromDatabase(day); 

 

 const netSales = totalSales - returns; 

 

 // Update the cache with the calculated net sales 

 await segment.put(day, netSales, 2); 

 

 console.log(`Calculated net sales for ${day}: ${netSales}`); 

 return { day, netSales }; 

} 

 

app.get("/net-sales/:day", async (req, res) => { 

 const catalystApp = catalyst.initialize(req, { 

   type: catalyst.type.advancedio, 

 }); 

 

 const day = req.params.day; 

 // Add your segment ID. 

 const segment = await catalystApp.cache().segment("2603000000017001"); 

 

 // Calculate net sales for the specified day, considering caching 

 const netSales = await calculateNetSalesForDay(segment, day); 

 

 res.json(netSales); 

}); 

 

const port = 3000; 

app.listen(port, () => { 

 console.log(`Server listening on port ${port}`); 

}); 

 

module.exports = app; 

 

If tons of users coming to check the sales, sales cannot be calculate on each request, as the server may crash. Instead, we’ll calculate it once for the first request and then serve the data in subsequent requests. The results can be seen below. Since the calculated response is cached, it will be returned quickly

Screenshot of a computer screen displaying an api test environment interface with a response code 500 highlighted in red. Screenshot of a postman api request interface showing a get request to a url with json response data displayed in the body pane.

Zoho Catalyst Cache The Key to Accelerated App Performance 

Zoho Catalyst Cache stands out as a crucial tool for developers aiming to boost their application’s performance. By diving into its features and weaving it into Node.js applications, developers can tap into unprecedented efficiency levels, setting the stage for quicker app responses, lighter loads, and a superior user experience. Contact us to Adopt Zoho Catalyst Cache and take your Node.js applications to the next level of operational excellence. 

Steve Solt headshot

Mike Dranginis is the AVP of Zoho Development at KDG. Mike is dedicated to continuous self-improvement and is constantly striving to do better than his best. This is evident in the dozens of applications he has built and the numerous clients in manufacturing, higher ed, and retail that continue to come back with new ideas and new goals.

Want to learn more? Book a meeting with us today!

Recent Posts
KDG logo

Discover Zoho: The Path to Innovation and Growth

Leverage our expertise as the #1 Global Zoho Partner to streamline your business processes and enhance operational efficiency.

Share this post!

Explore More: Related Insights

  • Article
    Benefits of Custom Software Development: Boost Your Productivity
  • Article
    Beyond Data: Why UI in Reporting Matters
  • Article
    Implementing Technology Strategies for Scalable Nonprofit Operations