From 960ef9b87de770b6789ed1ae0222dc9ce2fd285f Mon Sep 17 00:00:00 2001
From: Dmitry9 <karpov.dmitry80@gmail.com>
Date: Mon, 6 May 2019 18:06:32 +0300
Subject: [PATCH] feat(Cargo): cache GitHub-cratesio-index requests for 10
 minutes

---
 lib/datasource/cargo/index.js | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lib/datasource/cargo/index.js b/lib/datasource/cargo/index.js
index 741b259208..20ad10cb88 100644
--- a/lib/datasource/cargo/index.js
+++ b/lib/datasource/cargo/index.js
@@ -8,6 +8,15 @@ async function getPkgReleases({ lookupName }) {
   if (!lookupName) {
     return null;
   }
+
+  const cacheNamespace = 'cargo';
+  const cacheKey = lookupName;
+  const cachedResult = await renovateCache.get(cacheNamespace, cacheKey);
+  // istanbul ignore if
+  if (cachedResult) {
+    return cachedResult;
+  }
+
   const len = lookupName.length;
   let path;
   // Ignored because there is no way to test this without hitting up GitHub API
@@ -74,6 +83,9 @@ async function getPkgReleases({ lookupName }) {
       }
       return release;
     });
+
+    const cacheMinutes = 10;
+    await renovateCache.set(cacheNamespace, cacheKey, result, cacheMinutes);
     return result;
   } catch (err) {
     if (err.statusCode === 404 || err.code === 'ENOTFOUND') {
-- 
GitLab