Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/build/cache.rb')
-rw-r--r--lib/gitlab/ci/build/cache.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/gitlab/ci/build/cache.rb b/lib/gitlab/ci/build/cache.rb
new file mode 100644
index 00000000000..4fcb5168847
--- /dev/null
+++ b/lib/gitlab/ci/build/cache.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ module Build
+ class Cache
+ include ::Gitlab::Utils::StrongMemoize
+
+ def initialize(cache, pipeline)
+ if multiple_cache_per_job?
+ cache = Array.wrap(cache)
+ @cache = cache.map do |cache|
+ Gitlab::Ci::Pipeline::Seed::Build::Cache
+ .new(pipeline, cache)
+ end
+ else
+ @cache = Gitlab::Ci::Pipeline::Seed::Build::Cache
+ .new(pipeline, cache)
+ end
+ end
+
+ def cache_attributes
+ strong_memoize(:cache_attributes) do
+ if multiple_cache_per_job?
+ if @cache.empty?
+ {}
+ else
+ { options: { cache: @cache.map(&:attributes) } }
+ end
+ else
+ @cache.build_attributes
+ end
+ end
+ end
+
+ private
+
+ def multiple_cache_per_job?
+ strong_memoize(:multiple_cache_per_job) do
+ ::Gitlab::Ci::Features.multiple_cache_per_job?
+ end
+ end
+ end
+ end
+ end
+end