varnish_rails 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c7c264ce3fbe73da472d2641fb65216e1be68aa5e1e4c870f532bf354868a6a
|
4
|
+
data.tar.gz: fbfe5c33ae393126e6643bddb84244565f3ed426c8a76e55667824daf70bd90c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4af0f348ce5090a090051724c506a59420f2ad8cd84cee32cc228f8e26b0a141c95c24803aee7e49434ad5068a674460e17514abbab92f672fbf0b136675b753
|
7
|
+
data.tar.gz: e959d239f816fa2a8ace0a414fe08ebfc51f6656f5e552c5b1e4cf635fe6e08dda0adb310e5fdd8a817484584b73d925a884487e3b223c93ce753258d7aff966
|
@@ -23,6 +23,12 @@ VarnishRails.configure do |config|
|
|
23
23
|
|
24
24
|
# Print requests
|
25
25
|
config.print_requests = ENV['VARNISH_PRINT_REQUESTS'] == "true" ? true : false
|
26
|
+
|
27
|
+
# Includes the access to purge to the following models (empty means all models access)
|
28
|
+
config.included_models = []
|
29
|
+
|
30
|
+
# Excludes the access to purge to the following models (empty means all models access)
|
31
|
+
config.excluded_models = []
|
26
32
|
end
|
27
33
|
|
28
34
|
# Flush the Varnish cache when the app starts
|
data/lib/varnish_rails.rb
CHANGED
@@ -26,7 +26,7 @@ module VarnishRails
|
|
26
26
|
end
|
27
27
|
|
28
28
|
class Configuration
|
29
|
-
attr_accessor :enable, :url, :maxage_key, :maxage_value, :xkey_length, :header_xkey_purge, :header_x_ban_url, :print_requests
|
29
|
+
attr_accessor :enable, :url, :maxage_key, :maxage_value, :xkey_length, :header_xkey_purge, :header_x_ban_url, :print_requests, :included_models, :excluded_models
|
30
30
|
|
31
31
|
def initialize
|
32
32
|
@enable = false
|
@@ -37,6 +37,8 @@ module VarnishRails
|
|
37
37
|
@header_xkey_purge = 'xkey-purge'
|
38
38
|
@header_x_ban_url = 'x-ban-url'
|
39
39
|
@print_requests = false
|
40
|
+
@included_models = nil
|
41
|
+
@excluded_models = nil
|
40
42
|
end
|
41
43
|
end
|
42
44
|
# CONFIGURATION -----------------------------------------------------------------
|
@@ -27,7 +27,6 @@ module ApplicationRecordMethods
|
|
27
27
|
# == Scopes ===============================================================
|
28
28
|
|
29
29
|
# == Instance Methods =====================================================
|
30
|
-
|
31
30
|
def varnish_configure
|
32
31
|
self.class.varnish_purge_on_commit = true if self.class.varnish_purge_on_commit.nil?
|
33
32
|
end
|
@@ -55,11 +54,17 @@ module ApplicationRecordMethods
|
|
55
54
|
end
|
56
55
|
|
57
56
|
def purge_cache_by_varnish_id
|
58
|
-
VarnishRailsService::purge_xkey_cache(varnish_id, varnish_class_name_fk) if (varnish_id.present? && !/.+::Translation/.match(self.class.name) && self.class.varnish_purge_on_commit)
|
57
|
+
VarnishRailsService::purge_xkey_cache(varnish_id, varnish_class_name_fk) if (self.class.can_purge && varnish_id.present? && !/.+::Translation/.match(self.class.name) && self.class.varnish_purge_on_commit)
|
59
58
|
end
|
60
59
|
|
61
60
|
# == Class Methods ========================================================
|
62
61
|
|
62
|
+
def self.can_purge
|
63
|
+
return VarnishRails.configuration.included_models.include?(self::name) if VarnishRails.configuration.included_models.present?
|
64
|
+
return !VarnishRails.configuration.excluded_models.include?(self::name) if VarnishRails.configuration.excluded_models.present?
|
65
|
+
return true
|
66
|
+
end
|
67
|
+
|
63
68
|
def self.varnish_class_name(namespace='')
|
64
69
|
class_name = namespace.present? ? [self.name, namespace].join('-') : self.name
|
65
70
|
return self.varnish_encode(class_name)
|
@@ -77,7 +82,7 @@ module ApplicationRecordMethods
|
|
77
82
|
end
|
78
83
|
|
79
84
|
def self.purge_cache_by_varnish_class_name
|
80
|
-
VarnishRailsService::purge_xkey_cache(self::varnish_class_name, self::varnish_class_name_fk) if self::varnish_purge_on_commit
|
85
|
+
VarnishRailsService::purge_xkey_cache(self::varnish_class_name, self::varnish_class_name_fk) if (self::can_purge && self::varnish_purge_on_commit)
|
81
86
|
end
|
82
87
|
|
83
88
|
def self.varnish_encode(value)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: varnish_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iXmedia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|