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/pages/cache_control.rb')
-rw-r--r--lib/gitlab/pages/cache_control.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/gitlab/pages/cache_control.rb b/lib/gitlab/pages/cache_control.rb
new file mode 100644
index 00000000000..991a1297d03
--- /dev/null
+++ b/lib/gitlab/pages/cache_control.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Pages
+ class CacheControl
+ CACHE_KEY_FORMAT = 'pages_domain_for_%{type}_%{id}'
+
+ attr_reader :cache_key
+
+ class << self
+ def for_project(project_id)
+ new(type: :project, id: project_id)
+ end
+
+ def for_namespace(namespace_id)
+ new(type: :namespace, id: namespace_id)
+ end
+ end
+
+ def initialize(type:, id:)
+ raise(ArgumentError, "type must be :namespace or :project") unless %i[namespace project].include?(type)
+
+ @cache_key = CACHE_KEY_FORMAT % { type: type, id: id }
+ end
+
+ def clear_cache
+ Rails.cache.delete(cache_key)
+ end
+ end
+ end
+end