ar_cache 1.5.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rails/generators'
4
- require 'rails/generators/migration'
5
- require 'rails/generators/active_record/migration'
6
4
 
7
5
  module ArCache
8
6
  module Generators
9
7
  class InstallGenerator < Rails::Generators::Base
10
- include Rails::Generators::Migration
11
- include ::ActiveRecord::Generators::Migration
12
-
13
8
  source_root File.expand_path('templates', __dir__)
14
9
 
15
10
  def copy_initializer_file
16
11
  copy_file 'configuration.rb', 'config/initializers/ar_cache.rb'
17
-
18
- migration_template 'migrate/create_ar_cache_records.rb', 'db/migrate/create_ar_cache_records.rb'
19
12
  end
20
13
  end
21
14
  end
@@ -2,32 +2,28 @@
2
2
 
3
3
  # For more information, please see: https://github.com/OuYangJinTing/ar_cache/README.md
4
4
  ArCache.configure do |config|
5
- # WARNING: The should uncomment only when your database default isolation level is "READ UNCOMMITTED"!
6
- # config.read_uncommitted = true # defaul false
5
+ # NOTE: Please change true if database happened some problems
6
+ # Arcache default use database share lock to ensure that the cache is correct.
7
+ config.cache_lock = false # Boolean
7
8
 
8
- # config.cache_store = ActiveSupport::Cache::Store # default Rails.cache || ActiveSupport::Cache::MemoryStore.new
9
+ # The cache tool.
10
+ config.cache_store = defined?(Rails) ? Rails.cache : ActiveSupport::Cache::MemoryStore.new
9
11
 
10
- # Cache key automatic expiration time.
11
- # config.expires_in = Numeric # default 1 week
12
-
13
- # Serialize and deserialize cached data.
14
- # config.coder = [YAML|JSON] # default YAML
15
-
16
- # Support the maximum length of index column value.
17
- # config.column_length = Integer # default 64
12
+ # The cache key valid time.
13
+ config.expires_in = 1.week # Integer
18
14
 
19
15
  # ArCache switch.
20
- # config.disabled = Boolean # default false
21
-
22
- # Whether to support selecct columns query
23
- # config.select_disabled = Boolean # default true
24
-
25
- # config.tables_options = {
26
- # table_name: {
27
- # disabled: Boolean,
28
- # select_disabled: Boolean,
29
- # unique_indexes: Array # eg: [:id, [:name, :statue]], The default is the unique index column of the table.
30
- # },
31
- # ...
32
- # }
16
+ config.disabled = false # Boolean
17
+
18
+ # Whether to support select column sql.
19
+ config.select_disabled = true # Boolean
20
+
21
+ config.tables_options = {
22
+ # table_name: {
23
+ # disabled: Boolean,
24
+ # select_disabled: Boolean,
25
+ # unique_indexes: Array # eg: [:id, [:name, :statue]], The default is the unique index column of the table.
26
+ # },
27
+ # ...
28
+ }
33
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OuYangJinTing
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-22 00:00:00.000000000 Z
11
+ date: 2021-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -30,6 +30,26 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '7'
33
+ - !ruby/object:Gem::Dependency
34
+ name: oj
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '3'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '4'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '3'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '4'
33
53
  description: An modern cacheing library for ActiveRecord inspired by cache-money and
34
54
  second_level_cache.
35
55
  email:
@@ -48,6 +68,7 @@ files:
48
68
  - Gemfile.lock
49
69
  - LICENSE.txt
50
70
  - README.md
71
+ - README.zh-CN.md
51
72
  - Rakefile
52
73
  - ar_cache.gemspec
53
74
  - bin/activerecord-test
@@ -72,14 +93,11 @@ files:
72
93
  - lib/ar_cache/marshal.rb
73
94
  - lib/ar_cache/mock_table.rb
74
95
  - lib/ar_cache/query.rb
75
- - lib/ar_cache/record.rb
76
- - lib/ar_cache/store.rb
77
96
  - lib/ar_cache/table.rb
78
97
  - lib/ar_cache/version.rb
79
98
  - lib/ar_cache/where_clause.rb
80
99
  - lib/generators/ar_cache/install_generator.rb
81
100
  - lib/generators/ar_cache/templates/configuration.rb
82
- - lib/generators/ar_cache/templates/migrate/create_ar_cache_records.rb.tt
83
101
  homepage: https://github.com/OuYangJinTing/ar_cache
84
102
  licenses:
85
103
  - MIT
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ArCache
4
- class Record < ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord
5
- self.table_name = 'ar_cache_records'
6
-
7
- def self.get(table_name)
8
- find_by(table_name: table_name)
9
- end
10
-
11
- def self.version(table)
12
- (get(table.name) || store(table)).version
13
- end
14
-
15
- def self.update_version(table)
16
- record = get(table.name)
17
- return store(table).version unless record
18
-
19
- record.update_version
20
- record.version
21
- end
22
-
23
- def self.store(table)
24
- record = get(table.name) || new(table_name: table.name)
25
- record.store(table)
26
- record
27
- end
28
-
29
- def store(table)
30
- with_optimistic_retry do
31
- self.version += 1 unless table_md5 == table.md5
32
- self.table_md5 = table.md5
33
-
34
- save! if changed?
35
- end
36
- end
37
-
38
- def update_version
39
- with_optimistic_retry do
40
- self.version += 1
41
- save!
42
- end
43
- end
44
-
45
- private def with_optimistic_retry
46
- yield
47
- rescue ::ActiveRecord::StaleObjectError
48
- reload
49
- retry
50
- end
51
- end
52
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ArCache
4
- class Store
5
- @options = { raw: true, expires_in: ArCache::Configuration.expires_in }.freeze
6
-
7
- class << self
8
- delegate :delete, :delete_multi, :clear, :exist?, to: 'ArCache::Configuration.cache_store'
9
-
10
- def write(name, value)
11
- ArCache::Configuration.cache_store.write(name, dump(value), @options)
12
- end
13
-
14
- def write_multi(hash)
15
- hash.each { |k, v| hash[k] = dump(v) }
16
- ArCache::Configuration.cache_store.write_multi(hash, @options)
17
- end
18
-
19
- def read(name)
20
- load(ArCache::Configuration.cache_store.read(name, @options))
21
- end
22
-
23
- def read_multi(names)
24
- entries = ArCache::Configuration.cache_store.read_multi(*names, @options)
25
- entries.each { |k, v| entries[k] = load(v) }
26
- entries
27
- end
28
-
29
- private def dump(value)
30
- ArCache::Configuration.coder.dump(value)
31
- end
32
-
33
- private def load(value)
34
- ArCache::Configuration.coder.load(value) if value
35
- end
36
- end
37
- end
38
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class CreateArCacheMonitors < ActiveRecord::Migration[<%= ActiveRecord::VERSION::MAJOR %>.<%= ActiveRecord::VERSION::MINOR %>]
4
- def change
5
- create_table :ar_cache_records do |t|
6
- t.string :table_name, null: false
7
- t.string :table_md5, null: false, limit: 32, default: '0' * 32
8
- t.integer :version, null: false, default: 0
9
- t.integer :lock_version, null: false, default: 0
10
-
11
- t.timestamps null: false
12
-
13
- t.index :table_name, unique: true
14
- end
15
- end
16
- end