Class: OpenAssets::Cache::SSLCertificateCache
- Inherits:
-
SQLiteBase
- Object
- SQLiteBase
- OpenAssets::Cache::SSLCertificateCache
- Defined in:
- lib/openassets/cache/ssl_certificate_cache.rb
Instance Attribute Summary
Attributes inherited from SQLiteBase
Instance Method Summary collapse
-
#get(url) ⇒ Object
Return the subject value which defined by ssl certificate.
-
#initialize ⇒ SSLCertificateCache
constructor
A new instance of SSLCertificateCache.
-
#put(url, subject, expire_date) ⇒ Object
Saves a serialized transaction in cache.
- #setup ⇒ Object
Constructor Details
#initialize ⇒ SSLCertificateCache
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
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
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 |
#setup ⇒ Object
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 |