Class: OpenAssets::Cache::SSLCertificateCache

Inherits:
SQLiteBase
  • Object
show all
Defined in:
lib/openassets/cache/ssl_certificate_cache.rb

Instance Attribute Summary

Attributes inherited from SQLiteBase

#db

Instance Method Summary collapse

Constructor Details

#initializeSSLCertificateCache

Returns a new instance of SSLCertificateCache.



5
6
7
8
# File 'lib/openassets/cache/ssl_certificate_cache.rb', line 5

def initialize
  path = OpenAssets.configuration ? OpenAssets.configuration[:cache] : ':memory:'
  super(path)
end

Instance Method Details

#get(url) ⇒ Object

Return the subject value which defined by ssl certificate. @param url The URL of asset definition file. @return The subject value. If not found, return nil.



23
24
25
26
27
28
29
30
31
32
# File 'lib/openassets/cache/ssl_certificate_cache.rb', line 23

def get(url)
  rows = db.execute('SELECT Subject,ExpireDate FROM SslCertificate WHERE Url = ?', [url])
  return nil if rows.empty?
  if rows[0][1].to_i < Time.now.to_i
    db.execute('DELETE FROM SslCertificate where Url = ?', [url])
    nil
  else
    rows[0][0]
  end
end

#put(url, subject, expire_date) ⇒ Object

Saves a serialized transaction in cache. @param url The URL of asset definition file. @param subject The SSL Certificate subject value. @param expire_date The expire date of SSL Certificate.



38
39
40
# File 'lib/openassets/cache/ssl_certificate_cache.rb', line 38

def put(url, subject, expire_date)
  db.execute('INSERT INTO SslCertificate (Url, Subject, ExpireDate) VALUES (?, ?, ?)', [url, subject, expire_date.to_i])
end

#setupObject



10
11
12
13
14
15
16
17
18
# File 'lib/openassets/cache/ssl_certificate_cache.rb', line 10

def setup
  db.execute <<-SQL
    CREATE TABLE IF NOT EXISTS SslCertificate(
            Url TEXT,
            Subject TEXT,
            ExpireDate TEXT,
            PRIMARY KEY (Url))
  SQL
end