Class: CollectionSpace::RefCache

Inherits:
Object
  • Object
show all
Defined in:
lib/collectionspace/refcache/version.rb,
lib/collectionspace/refcache/backend.rb,
lib/collectionspace/refcache/refcache.rb,
lib/collectionspace/refcache/backend/redis.rb,
lib/collectionspace/refcache/backend/zache.rb

Overview

rubocop:disable Style/StaticClass

Defined Under Namespace

Modules: Backend Classes: NotFoundError

Constant Summary collapse

VERSION =
"1.0.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: {}) ⇒ RefCache

Returns a new instance of RefCache.



11
12
13
14
15
16
17
# File 'lib/collectionspace/refcache/refcache.rb', line 11

def initialize(config: {})
  @config = config
  @cache = backend(config.fetch(:redis, nil))
  @domain = config.fetch(:domain)
  @error_if_not_found = config.fetch(:error_if_not_found, false)
  @lifetime = config.fetch(:lifetime, 5 * 60)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/collectionspace/refcache/refcache.rb', line 9

def config
  @config
end

#domainObject (readonly)

Returns the value of attribute domain.



9
10
11
# File 'lib/collectionspace/refcache/refcache.rb', line 9

def domain
  @domain
end

Instance Method Details

#auth_term_exists?(type, subtype, term) ⇒ Boolean

authority term caching

Returns:

  • (Boolean)


108
109
110
# File 'lib/collectionspace/refcache/refcache.rb', line 108

def auth_term_exists?(type, subtype, term)
  generic_exists?(term_key(type, subtype, term))
end

#cleanObject

deletes expired keys (run using cron etc.)



24
25
26
# File 'lib/collectionspace/refcache/refcache.rb', line 24

def clean
  @cache.clean
end

#connected?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/collectionspace/refcache/refcache.rb', line 28

def connected?
  @cache.connected?
end

#exists?(type, subtype, value) ⇒ Boolean

Default methods (assumes authority terms) cache.exists?(‘placeauthorities’, ‘place’, ‘Death Valley’)

Returns:

  • (Boolean)


46
47
48
# File 'lib/collectionspace/refcache/refcache.rb', line 46

def exists?(type, subtype, value)
  generic_exists?(term_key(type, subtype, value))
end

#flushObject

delete all keys from the cache

If Redis backend, only deletes keys from active database



35
36
37
# File 'lib/collectionspace/refcache/refcache.rb', line 35

def flush
  @cache.flush
end

#get(type, subtype, value) ⇒ Object

cache.get(‘placeauthorities’, ‘place’, ‘The Moon’) cache.get(‘vocabularies’, ‘languages’, ‘English’)



59
60
61
# File 'lib/collectionspace/refcache/refcache.rb', line 59

def get(type, subtype, value)
  get_generic(term_key(type, subtype, value))
end

#get_auth_term(type, subtype, term) ⇒ Object

rubocop:enable Metrics/ParameterLists



118
119
120
# File 'lib/collectionspace/refcache/refcache.rb', line 118

def get_auth_term(type, subtype, term)
  get_generic(term_key(type, subtype, term))
end

#get_object(id) ⇒ Object



74
75
76
# File 'lib/collectionspace/refcache/refcache.rb', line 74

def get_object(id)
  get_generic(object_key(id))
end

#get_procedure(type, id) ⇒ Object



93
94
95
# File 'lib/collectionspace/refcache/refcache.rb', line 93

def get_procedure(type, id)
  get_generic(procedure_key(type, id))
end

#get_relation(reltype, subjectcsid, objectcsid) ⇒ Object

rubocop:enable Metrics/ParameterLists



139
140
141
# File 'lib/collectionspace/refcache/refcache.rb', line 139

def get_relation(reltype, subjectcsid, objectcsid)
  get_generic(term_key(reltype, subjectcsid, objectcsid))
end

#get_vocab_term(vocab, term) ⇒ Object

rubocop:enable Metrics/ParameterLists



160
161
162
# File 'lib/collectionspace/refcache/refcache.rb', line 160

def get_vocab_term(vocab, term)
  get_generic(vocab_term_key(vocab, term))
end

#object_exists?(id) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/collectionspace/refcache/refcache.rb', line 82

def object_exists?(id)
  generic_exists?(object_key(id))
end

#procedure_exists?(type, id) ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/collectionspace/refcache/refcache.rb', line 101

def procedure_exists?(type, id)
  generic_exists?(procedure_key(type, id))
end

#put(type, subtype, value, to_cache) ⇒ Object

cache.put(‘placeauthorities’, ‘place’, ‘The Moon’, $refname) rubocop:disable Metrics/ParameterLists



52
53
54
# File 'lib/collectionspace/refcache/refcache.rb', line 52

def put(type, subtype, value, to_cache)
  put_generic(term_key(type, subtype, value), to_cache)
end

#put_auth_term(type, subtype, term, to_cache) ⇒ Object

rubocop:disable Metrics/ParameterLists



113
114
115
# File 'lib/collectionspace/refcache/refcache.rb', line 113

def put_auth_term(type, subtype, term, to_cache)
  put_generic(term_key(type, subtype, term), to_cache)
end

#put_object(id, to_cache) ⇒ Object

object caching



70
71
72
# File 'lib/collectionspace/refcache/refcache.rb', line 70

def put_object(id, to_cache)
  put_generic(object_key(id), to_cache)
end

#put_procedure(type, id, to_cache) ⇒ Object

procedure caching



89
90
91
# File 'lib/collectionspace/refcache/refcache.rb', line 89

def put_procedure(type, id, to_cache)
  put_generic(procedure_key(type, id), to_cache)
end

#put_relation(reltype, subjectcsid, objectcsid, to_cache) ⇒ Object

rubocop:disable Metrics/ParameterLists



134
135
136
# File 'lib/collectionspace/refcache/refcache.rb', line 134

def put_relation(reltype, subjectcsid, objectcsid, to_cache)
  put_generic(term_key(reltype, subjectcsid, objectcsid), to_cache)
end

#put_vocab_term(vocab, term, to_cache) ⇒ Object

rubocop:disable Metrics/ParameterLists



155
156
157
# File 'lib/collectionspace/refcache/refcache.rb', line 155

def put_vocab_term(vocab, term, to_cache)
  put_generic(vocab_term_key(vocab, term), to_cache)
end

#relation_exists?(reltype, subjectcsid, objectcsid) ⇒ Boolean

relation caching

Returns:

  • (Boolean)


129
130
131
# File 'lib/collectionspace/refcache/refcache.rb', line 129

def relation_exists?(reltype, subjectcsid, objectcsid)
  generic_exists?(term_key(reltype, subjectcsid, objectcsid))
end

#remove(type, subtype, value) ⇒ Object



63
64
65
# File 'lib/collectionspace/refcache/refcache.rb', line 63

def remove(type, subtype, value)
  remove_generic(term_key(type, subtype, value))
end

#remove_auth_term(type, subtype, term) ⇒ Object



122
123
124
# File 'lib/collectionspace/refcache/refcache.rb', line 122

def remove_auth_term(type, subtype, term)
  remove_generic(term_key(type, subtype, term))
end

#remove_object(id) ⇒ Object



78
79
80
# File 'lib/collectionspace/refcache/refcache.rb', line 78

def remove_object(id)
  remove_generic(object_key(id))
end

#remove_procedure(type, id) ⇒ Object



97
98
99
# File 'lib/collectionspace/refcache/refcache.rb', line 97

def remove_procedure(type, id)
  remove_generic(procedure_key(type, id))
end

#remove_relation(reltype, subjectcsid, objectcsid) ⇒ Object



143
144
145
# File 'lib/collectionspace/refcache/refcache.rb', line 143

def remove_relation(reltype, subjectcsid, objectcsid)
  remove_generic(term_key(reltype, subjectcsid, objectcsid))
end

#remove_vocab_term(vocab, term) ⇒ Object



164
165
166
# File 'lib/collectionspace/refcache/refcache.rb', line 164

def remove_vocab_term(vocab, term)
  remove_generic(vocab_term_key(vocab, term))
end

#sizeObject



39
40
41
# File 'lib/collectionspace/refcache/refcache.rb', line 39

def size
  @cache.size
end

#vocab_term_exists?(vocab, term) ⇒ Boolean

vocabulary term caching

Returns:

  • (Boolean)


150
151
152
# File 'lib/collectionspace/refcache/refcache.rb', line 150

def vocab_term_exists?(vocab, term)
  generic_exists?(vocab_term_key(vocab, term))
end