db_memoize 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -41
- data/VERSION +1 -1
- data/lib/db_memoize/migrations.rb +15 -18
- data/lib/db_memoize/value.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 104a42e53e91c5485d2babe2f22995633965025b6a9bf4790b54d1e7768aef45
|
4
|
+
data.tar.gz: 0301ec4568f6787036176431fbdaa327c7e564287b06b670ddc95396672f79fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fc1493d08f64346c0bc7cb9ff1da76ac0d6a32e6d7c9a42fc56e39f2cf174ab1c18f668410b3fd0015405847aa4cb204605028b41d0c71c13c93830157ec18d
|
7
|
+
data.tar.gz: 73d3a582bb4544a3c813794abe13e1aea4f6c40d298de3808ab648be76280c712fbbf2451061dc043d1fa4cb4e384450eeaf6fdbf70b5b1ce1871392388439ea
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
[![Build Status](https://travis-ci.com/mediapeers/db_memoize.svg?branch=master)](https://travis-ci.com/mediapeers/db_memoize)
|
2
2
|
|
3
3
|
# db_memoize
|
4
|
-
library to cache (memoize)
|
4
|
+
A library to cache (memoize) return values of methods in the database.
|
5
5
|
|
6
6
|
**Note:** when updating from version 0.1 to 0.2 you need to run a migration on the existing table, see below.
|
7
7
|
|
@@ -37,7 +37,7 @@ record.hello
|
|
37
37
|
|
38
38
|
will call the original method only once. Consecutive calls will return a cached value.
|
39
39
|
|
40
|
-
If the method takes arguments
|
40
|
+
If the method takes arguments...
|
41
41
|
|
42
42
|
record.hello('Maria')
|
43
43
|
record.hello('John')
|
@@ -68,7 +68,7 @@ Instead of ActiveRecord instances it's sufficient to pass in the ids of the reco
|
|
68
68
|
|
69
69
|
### Gotchas
|
70
70
|
|
71
|
-
|
71
|
+
The cached values themselves are active records (of type `DbMemoize::Value`) and are saved in the database. They are also registered as an association, so you can access all of the cached values of an object like this:
|
72
72
|
|
73
73
|
record.memoized_values
|
74
74
|
|
@@ -82,11 +82,11 @@ DbMemoize by default will write log output to STDOUT. You can change this by set
|
|
82
82
|
|
83
83
|
### Rake Tasks
|
84
84
|
|
85
|
-
To _warmup_ your cache you can pre-generate cached values via a rake task like this (only works for methods not
|
85
|
+
To _warmup_ your cache, you can pre-generate cached values via a rake task like this (only works for methods that do not take arguments):
|
86
86
|
|
87
87
|
bundle exec rake db_memoize:warmup class=Letter methods=hello,bye
|
88
88
|
|
89
|
-
Similarly you can wipe all cached values for a given class
|
89
|
+
Similarly, you can wipe all cached values for a given class:
|
90
90
|
|
91
91
|
bundle exec rake db_memoize:clear class=Letter
|
92
92
|
|
@@ -111,44 +111,14 @@ end
|
|
111
111
|
|
112
112
|
Note that db_memoize needs Postgres. To set up the database needed to run tests, this is what you can do:
|
113
113
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
### Updating from 0.1 -> 0.2
|
120
|
-
|
121
|
-
You need to run a migration, like the following:
|
122
|
-
|
123
|
-
```
|
124
|
-
class FixDbMemoizeTable < ActiveRecord::Migration
|
125
|
-
def up
|
126
|
-
# After updating db_memoize to 0.2 we need to update some structures, depending
|
127
|
-
# on whether or not db_memoize 0.1 or 0.2 was creating the database tables.
|
128
|
-
execute <<-SQL
|
129
|
-
ALTER TABLE memoized_values
|
130
|
-
ALTER COLUMN entity_table_name SET NOT NULL,
|
131
|
-
ALTER COLUMN entity_id SET NOT NULL,
|
132
|
-
ALTER COLUMN method_name SET NOT NULL,
|
133
|
-
ALTER COLUMN created_at SET NOT NULL;
|
134
|
-
DROP INDEX IF EXISTS index_memoized_values_on_entity_table_name_and_entity_id;
|
135
|
-
CREATE INDEX IF NOT EXISTS index_memoized_values_on_entity_id_and_entity_table_name
|
136
|
-
ON memoized_values(entity_id, entity_table_name);
|
137
|
-
CREATE INDEX IF NOT EXISTS memoized_attributes_idx
|
138
|
-
ON memoized_values (((arguments_hash IS NULL)))
|
139
|
-
SQL
|
140
|
-
end
|
141
|
-
|
142
|
-
def down
|
143
|
-
execute <<-SQL
|
144
|
-
DROP INDEX memoized_attributes_idx;
|
145
|
-
DROP INDEX index_memoized_values_on_entity_id_and_entity_table_name;
|
146
|
-
SQL
|
147
|
-
end
|
148
|
-
end
|
114
|
+
```sh
|
115
|
+
~/your/path> sudo su postgresql
|
116
|
+
~/your/path> createuser >>yourusername<
|
117
|
+
~/your/path> createdb -O >>yourusername<< db_memoize_test
|
149
118
|
```
|
150
119
|
|
151
|
-
Have fun!
|
152
120
|
|
121
|
+
### Updating from earlier versions
|
153
122
|
|
123
|
+
It is generally impossible to update from earlier versions and keep the cached data. DbMemoize should always be able to rerun migrations to update database structures to the latest version - feel free to add in as many migrations as you like :)
|
154
124
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.8
|
@@ -3,30 +3,27 @@ module DbMemoize
|
|
3
3
|
class << self
|
4
4
|
def create_tables(migration)
|
5
5
|
migration.execute <<~SQL
|
6
|
-
CREATE
|
6
|
+
CREATE SCHEMA IF NOT EXISTS db_memoize;
|
7
|
+
|
8
|
+
CREATE TABLE IF NOT EXISTS db_memoize.memoized_values (
|
7
9
|
entity_table_name varchar NOT NULL,
|
8
|
-
entity_id
|
9
|
-
method_name
|
10
|
-
|
10
|
+
entity_id integer NOT NULL,
|
11
|
+
method_name varchar NOT NULL,
|
12
|
+
|
13
|
+
val_string varchar,
|
14
|
+
val_integer bigint,
|
15
|
+
val_float double precision,
|
16
|
+
val_time timestamp without time zone,
|
17
|
+
val_object jsonb,
|
18
|
+
val_boolean boolean,
|
19
|
+
val_nil boolean,
|
20
|
+
created_at timestamp without time zone NOT NULL
|
11
21
|
);
|
12
22
|
|
13
23
|
-- entity_id/entity_table_name should have a better chance to be useful, since
|
14
24
|
-- there is more variance in entity_ids than there is in entity_table_names.
|
15
|
-
DROP INDEX IF EXISTS index_memoized_values_on_entity_id_and_entity_table_name;
|
16
|
-
DROP INDEX IF EXISTS index_memoized_values_on_entity_table_name_and_entity_id;
|
17
25
|
CREATE UNIQUE INDEX IF NOT EXISTS memoized_attributes_idx2
|
18
|
-
ON memoized_values(entity_id, entity_table_name, method_name);
|
19
|
-
|
20
|
-
ALTER TABLE memoized_values DROP COLUMN IF EXISTS arguments_hash;
|
21
|
-
ALTER TABLE memoized_values DROP COLUMN IF EXISTS value;
|
22
|
-
|
23
|
-
ALTER TABLE memoized_values ADD COLUMN IF NOT EXISTS val_string varchar;
|
24
|
-
ALTER TABLE memoized_values ADD COLUMN IF NOT EXISTS val_integer bigint;
|
25
|
-
ALTER TABLE memoized_values ADD COLUMN IF NOT EXISTS val_float double precision;
|
26
|
-
ALTER TABLE memoized_values ADD COLUMN IF NOT EXISTS val_time timestamp without time zone;
|
27
|
-
ALTER TABLE memoized_values ADD COLUMN IF NOT EXISTS val_object jsonb;
|
28
|
-
ALTER TABLE memoized_values ADD COLUMN IF NOT EXISTS val_boolean boolean;
|
29
|
-
ALTER TABLE memoized_values ADD COLUMN IF NOT EXISTS val_nil boolean;
|
26
|
+
ON db_memoize.memoized_values(entity_id, entity_table_name, method_name);
|
30
27
|
SQL
|
31
28
|
end
|
32
29
|
end
|
data/lib/db_memoize/value.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db_memoize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- johannes-kostas goetzinger
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simple-sql
|