Create a robust, time-to-live (TTL) aware data cache using n8n Data Tables. This reusable n8n workflow template handles reads, writes, and automated cleanup.
Download this n8n workflow template and start using it instantly.
Automation Architects: Building reusable infrastructure components within n8n. Developers: Needing to minimize API calls or manage state across multiple n8n workflow executions.* Performance Enthusiasts: Looking to implement rapid, self-hosted data lookup mechanisms within their n8n templates.
This advanced n8n workflow template demonstrates how to build a vital piece of infrastructure: a reliable data cache, without relying on external services like Redis. This specific n8n workflow utilizes the powerful n8n Data Table n8n node in an 'upsert' (write) and 'get' (read) manner to manage key-value pairs with an expiration (TTL).
Implementing this cache is essential for minimizing API calls, improving the performance of resource-intensive n8n templates, and reducing external service costs. This complete n8n solution includes two key operational components: a sub-workflow n8n trigger for on-demand cache operations (read/write) and an independent hourly n8n trigger for automated cache cleanup and maintenance.
Important Setup Note: This n8n workflow requires an n8n Data Table named cache with columns key (string), ttl (datetime), and value (string).
The core logic of this n8n workflow is split into a sub-workflow execution path and a cleanup path.
cacheKey, writeValue, and trueToWrite. The 'Check Action Type' n8n node determines if the request is a 'write' (if trueToWrite is true) or a 'read' operation.writeValue and calculating the ttl by adding the input writeTTLms to the current time ($now). The written value is then returned.cacheKey.ttl is before the current $now, the flow proceeds to 'No cache found...' (Stop and Error), signaling the calling n8n workflow that the cache needs to be refreshed.deleteRows operation where the ttl field is less than the current date and time ($now). This keeps the underlying Data Table small and performant.cache (all lowercase) and ensure it has the following exact columns:key: stringttl: datetimevalue: stringcache table. When Executed by Another Workflow (n8n trigger): The entry point for cache operations. It defines the necessary inputs (cacheKey, writeValue, trueToWrite, writeTTLms) required by the calling n8n workflow.
Check Action Type (If n8n node): Determines if the sub-workflow call is a read or a write based on the input boolean trueToWrite.
Upsert row(s) (Data Table n8n node): Handles cache writing. It uses expressions to set the key for matching and calculates the ttl by adding the writeTTLms input to $now.
Get row(s) (Data Table n8n node): Handles cache reading by filtering the Data Table based on the incoming cacheKey.
If not in Cache / If Expired Cache (If n8n node): Core flow control nodes that enforce cache validation. They check for the existence of the row and compare the stored ttl value against $now to determine validity.
No cache found, use error detection to detect this. (Stop and Error n8n node): Used to terminate the n8n workflow with a specific error message if the requested key is missing or expired, allowing the parent n8n workflow to handle the cache miss.
1 Hour Clean for Cache Table (Schedule n8n trigger): An independent n8n trigger that runs maintenance tasks hourly.
Drop all rows with expired cache entires (Data Table n8n node): Performs the cleanup operation, deleting rows where the ttl is less than the current time.
Deploy an advanced n8n workflow for a stateful Telegram chatbot using GPT-4o-mini and Google Sheets for persistent session management, summarization, and contextual Q&A.

Use this comprehensive n8n workflow to build a dynamic Retrieval-Augmented Generation (RAG) system. Sync Google Drive files to Supabase vectors using the Google Gemini n8n node.

Deploy a powerful, self-hosted blockchain payment processor using this advanced n8n workflow. Integrate the x402 protocol with 1Shot API to manage verified, secure crypto payments across multiple chains. Download these n8n templates today.

Build a powerful, context-aware Slack AI chatbot using this advanced n8n workflow. Integrate OpenRouter, persistent Postgres memory, and a 'thinking' UI for superior user experience. Get this complete n8n template now.









































