Tableau simple comme cache
Intermédiaire
Ceci est uncontenant 15 nœuds.Utilise principalement des nœuds comme If, Set, DataTable, StopAndError, ScheduleTrigger. Créer un simple système de cache de données sans dépendances externes
Prérequis
- •Aucun prérequis spécial, prêt à l'emploi après importation
Catégorie
-
Aperçu du workflow
Visualisation des connexions entre les nœuds, avec support du zoom et du déplacement
Exporter le workflow
Copiez la configuration JSON suivante dans n8n pour importer et utiliser ce workflow
{
"name": "Simple Table as Cache",
"nodes": [
{
"id": "ae9f420d-1e6b-48d7-a064-7486ddd05f5f",
"name": "When Executed by Another Workflow",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"notes": "To write set the value to true.\nTTL is in milliseconds",
"position": [
-16,
-96
],
"parameters": {
"workflowInputs": {
"values": [
{
"name": "trueToWrite",
"type": "boolean"
},
{
"name": "cacheKey"
},
{
"name": "writeValue",
"type": "any"
},
{
"name": "writeTTLms",
"type": "number"
}
]
}
},
"typeVersion": 1.1
},
{
"id": "46e0b000-b24c-467a-9b1a-c50eebbf4b57",
"name": "Upsert row(s)",
"type": "n8n-nodes-base.dataTable",
"position": [
656,
-192
],
"parameters": {
"columns": {
"value": {
"key": "={{ $json.cacheKey }}",
"ttl": "={{ $now.plus($json.writeTTLms > 0 ? $json.writeTTLms : 10000) }}",
"value": "={{ JSON.stringify($json.writeValue) }}"
},
"schema": [
{
"id": "key",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "key",
"defaultMatch": false
},
{
"id": "value",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "value",
"defaultMatch": false
},
{
"id": "ttl",
"type": "dateTime",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "ttl",
"defaultMatch": false
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"filters": {
"conditions": [
{
"keyName": "key",
"keyValue": "={{ $json.cacheKey }}"
}
]
},
"operation": "upsert",
"dataTableId": {
"__rl": true,
"mode": "list",
"value": "RO0ChvBMPizGf4bb",
"cachedResultUrl": "/projects/IMwUHp4OzaUhAJNR/datatables/RO0ChvBMPizGf4bb",
"cachedResultName": "cache"
}
},
"typeVersion": 1,
"alwaysOutputData": true
},
{
"id": "be98ade2-7c04-4ac8-863a-7b9fbc01f57a",
"name": "Return Value",
"type": "n8n-nodes-base.set",
"position": [
880,
-192
],
"parameters": {
"mode": "raw",
"options": {},
"jsonOutput": "={{ $('When Executed by Another Workflow').item.json.writeValue }}"
},
"typeVersion": 3.4
},
{
"id": "9d06984a-4645-4306-83b6-9d998d60f50c",
"name": "Action Write Value",
"type": "n8n-nodes-base.noOp",
"position": [
432,
-192
],
"parameters": {},
"typeVersion": 1
},
{
"id": "3341e665-6c30-4ccc-b598-5eaa2443a9e4",
"name": "Get row(s)",
"type": "n8n-nodes-base.dataTable",
"position": [
656,
0
],
"parameters": {
"filters": {
"conditions": [
{
"keyName": "key",
"keyValue": "={{ $json.cacheKey }}"
}
]
},
"operation": "get",
"dataTableId": {
"__rl": true,
"mode": "list",
"value": "RO0ChvBMPizGf4bb",
"cachedResultUrl": "/projects/IMwUHp4OzaUhAJNR/datatables/RO0ChvBMPizGf4bb",
"cachedResultName": "cache"
}
},
"typeVersion": 1,
"alwaysOutputData": true
},
{
"id": "96ae4530-e574-467a-95a9-095882c0161a",
"name": "If Expired Cache",
"type": "n8n-nodes-base.if",
"position": [
1104,
80
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "03943791-3760-46e3-ac12-028fdbd5b440",
"operator": {
"type": "dateTime",
"operation": "after"
},
"leftValue": "={{ $now }}",
"rightValue": "={{ DateTime.fromISO($json.ttl) }}"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "9254b2a6-d265-4c3e-931f-9487ed2dccf5",
"name": "Read Action",
"type": "n8n-nodes-base.noOp",
"position": [
432,
0
],
"parameters": {},
"typeVersion": 1
},
{
"id": "0a656812-609f-4b51-be4c-d364b42273a6",
"name": "Check Action Type",
"type": "n8n-nodes-base.if",
"position": [
208,
-96
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "cfe96997-a2c7-44d1-a270-798fa5fdbeee",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ !!$json.trueToWrite }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "f20a262f-1880-4b20-ab84-5849a2846a5d",
"name": "If not in Cache",
"type": "n8n-nodes-base.if",
"position": [
880,
0
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "a3e38df9-cfdc-4a30-943f-34b42c37eb63",
"operator": {
"type": "object",
"operation": "empty",
"singleValue": true
},
"leftValue": "={{ $json }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "1ca6a00f-3363-4252-aa72-1779dbc9e1e1",
"name": "Note adhésive",
"type": "n8n-nodes-base.stickyNote",
"position": [
-672,
-96
],
"parameters": {
"width": 592,
"height": 320,
"content": "## IMPORTANT READ THIS!\nThis flow ***Requires*** the Beta version of N8N Tables to function.\nYou will need a table called \"cache\" <- All lowercase.\nThat table will need the following columns, again all lowercase:\n1. key: string\n2. ttl: datetime\n3. value: string\n\n\nPlease create this table and update the two datatable nodes to point to this table."
},
"typeVersion": 1
},
{
"id": "ca4d32ac-31f9-4656-ba7f-b77fb0410cb1",
"name": "No cache found, use error detection to detect this.",
"type": "n8n-nodes-base.stopAndError",
"position": [
1328,
-96
],
"parameters": {
"errorMessage": "No Entry or Expired Cache Item."
},
"typeVersion": 1
},
{
"id": "fa7762d4-0cce-4b73-bc58-f8569e8a9b28",
"name": "Return Value from Cache",
"type": "n8n-nodes-base.set",
"position": [
1328,
128
],
"parameters": {
"mode": "raw",
"options": {},
"jsonOutput": "={{ JSON.parse($('Get row(s)').item.json.value) }}"
},
"typeVersion": 3.4
},
{
"id": "d1cbe73a-2810-4410-9e21-eb51e85a8b45",
"name": "Note adhésive1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-48,
-752
],
"parameters": {
"color": 5,
"width": 960,
"height": 544,
"content": "## How To Use\nCall this node via the Execute Sub-Flow node with the specified inputs.\n(Optional) You can also \"activate\" this flow to enable hourly cleaning of the cache table to help keep data sizes down.\n\n## Output\nThis subflow will return the JSON.parse() representation of the string currently stored at the key in the cache table. This will be the same value written by the cache write input to this node if it has not expired.\n\nIf no value is found in the cache table for the input key, then a error is thrown. Listen for this error by setting your error response mode to be <On Error: \"Continue (Using Error Output)\"> in the node settings.\n\n## Inputs\n#### Action Read Required\n\"cacheKey\": <any string>\n\n#### Action Write Required\n\"cacheKey\": <any string>\n\"trueToWrite\": true,\n\"writeValue\": <any value including null. You are limited to data size of the table string field so don't stuff 20MB of JSON here.>,\n\"writeTTLms\": <optional, any number above 0 as milliseconds. Defaults to 10000>"
},
"typeVersion": 1
},
{
"id": "fedbcf7d-d7e2-4920-b57c-8b2e026c9dbe",
"name": "1 Hour Clean for Cache Table",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
-16,
112
],
"parameters": {
"rule": {
"interval": [
{
"field": "hours"
}
]
}
},
"typeVersion": 1.2
},
{
"id": "8e086bcf-d753-4187-b93c-ed2406d600cb",
"name": "Drop all rows with expired cache entries",
"type": "n8n-nodes-base.dataTable",
"position": [
208,
112
],
"parameters": {
"filters": {
"conditions": [
{
"keyName": "ttl",
"keyValue": "={{ $now }}",
"condition": "lt"
}
]
},
"options": {
"dryRun": true
},
"operation": "deleteRows",
"dataTableId": {
"__rl": true,
"mode": "list",
"value": "RO0ChvBMPizGf4bb",
"cachedResultUrl": "/projects/IMwUHp4OzaUhAJNR/datatables/RO0ChvBMPizGf4bb",
"cachedResultName": "cache"
}
},
"typeVersion": 1
}
],
"connections": {
"3341e665-6c30-4ccc-b598-5eaa2443a9e4": {
"main": [
[
{
"node": "f20a262f-1880-4b20-ab84-5849a2846a5d",
"type": "main",
"index": 0
}
]
]
},
"9254b2a6-d265-4c3e-931f-9487ed2dccf5": {
"main": [
[
{
"node": "3341e665-6c30-4ccc-b598-5eaa2443a9e4",
"type": "main",
"index": 0
}
]
]
},
"46e0b000-b24c-467a-9b1a-c50eebbf4b57": {
"main": [
[
{
"node": "be98ade2-7c04-4ac8-863a-7b9fbc01f57a",
"type": "main",
"index": 0
}
]
]
},
"f20a262f-1880-4b20-ab84-5849a2846a5d": {
"main": [
[
{
"node": "ca4d32ac-31f9-4656-ba7f-b77fb0410cb1",
"type": "main",
"index": 0
}
],
[
{
"node": "96ae4530-e574-467a-95a9-095882c0161a",
"type": "main",
"index": 0
}
]
]
},
"96ae4530-e574-467a-95a9-095882c0161a": {
"main": [
[
{
"node": "ca4d32ac-31f9-4656-ba7f-b77fb0410cb1",
"type": "main",
"index": 0
}
],
[
{
"node": "fa7762d4-0cce-4b73-bc58-f8569e8a9b28",
"type": "main",
"index": 0
}
]
]
},
"0a656812-609f-4b51-be4c-d364b42273a6": {
"main": [
[
{
"node": "9d06984a-4645-4306-83b6-9d998d60f50c",
"type": "main",
"index": 0
}
],
[
{
"node": "9254b2a6-d265-4c3e-931f-9487ed2dccf5",
"type": "main",
"index": 0
}
]
]
},
"9d06984a-4645-4306-83b6-9d998d60f50c": {
"main": [
[
{
"node": "46e0b000-b24c-467a-9b1a-c50eebbf4b57",
"type": "main",
"index": 0
}
]
]
},
"fedbcf7d-d7e2-4920-b57c-8b2e026c9dbe": {
"main": [
[
{
"node": "8e086bcf-d753-4187-b93c-ed2406d600cb",
"type": "main",
"index": 0
}
]
]
},
"ae9f420d-1e6b-48d7-a064-7486ddd05f5f": {
"main": [
[
{
"node": "0a656812-609f-4b51-be4c-d364b42273a6",
"type": "main",
"index": 0
}
]
]
}
}
}Foire aux questions
Comment utiliser ce workflow ?
Copiez le code de configuration JSON ci-dessus, créez un nouveau workflow dans votre instance n8n et sélectionnez "Importer depuis le JSON", collez la configuration et modifiez les paramètres d'authentification selon vos besoins.
Dans quelles scénarios ce workflow est-il adapté ?
Intermédiaire
Est-ce payant ?
Ce workflow est entièrement gratuit et peut être utilisé directement. Veuillez noter que les services tiers utilisés dans le workflow (comme l'API OpenAI) peuvent nécessiter un paiement de votre part.
Workflows recommandés
AIe-mail分诊与GPT-4警报系统及Telegramnotification
AIe-mail分诊与GPT-4警报系统及Telegramnotification
If
Set
Gmail
+
If
Set
Gmail
104 NœudsPeter Joslyn
Support
Liens internes du blog Shopify
Génération automatique d'articles de blog pertinents pour Shopify avec text-embedding-3-small d'OpenAI
If
Set
Code
+
If
Set
Code
26 NœudsGeoffroy
Création de contenu
Automatisation du processus d'intégration en plusieurs étapes avec Google Sheets, Forms et notifications Gmail
Utiliser Google Sheets, Forms et les notifications Gmail pour automatiser un processus d'intégration multi-étapes
If
Set
Code
+
If
Set
Code
31 NœudsPollupAI
Ressources Humaines
Modération automatisée des spams Discord
Modération automatisée du spam sur Discord avec une combinaison d'IA et de collaboration humaine
If
Set
Code
+
If
Set
Code
30 NœudsJimleuk
Intelligence Artificielle
Tokens de renouvellement pour Facebook et Instagram
Renouvellement automatique des jetons Meta avec Graph API et stockage de données
If
Set
Data Table
+
If
Set
Data Table
13 NœudsGeoffroy
Rapport d'équipe hebdomadaire automatisé pour les groupes WhatsApp avec résumé par Gemini AI
Rapport hebdomadaire automatisé d'équipe pour les groupes WhatsApp avec un résumé Gemini AI
If
Set
Code
+
If
Set
Code
47 NœudsJamot
Gestion de projet
Informations sur le workflow
Niveau de difficulté
Intermédiaire
Nombre de nœuds15
Catégorie-
Types de nœuds8
Description de la difficulté
Auteur
JustCallMeBlue
@justcallmeblueLiens externes
Voir sur n8n.io →
Partager ce workflow