Class: WirisPlugin::StoreCache
- Inherits:
-
Object
- Object
- WirisPlugin::StoreCache
- Extended by:
- CacheInterface
- Includes:
- Wiris
- Defined in:
- lib/com/wiris/util/sys/StoreCache.rb
Instance Attribute Summary collapse
-
#cachedir ⇒ Object
Returns the value of attribute cachedir.
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #deleteAll ⇒ Object
- #deleteStorageDir(s) ⇒ Object
- #get(key) ⇒ Object
- #getItemStore(key) ⇒ Object
-
#initialize(cachedir) ⇒ StoreCache
constructor
A new instance of StoreCache.
- #set(key, value) ⇒ Object
Methods included from CacheInterface
Constructor Details
#initialize(cachedir) ⇒ StoreCache
Returns a new instance of StoreCache.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/com/wiris/util/sys/StoreCache.rb', line 11 def initialize(cachedir) super() self.cachedir = Storage::newStorage(cachedir) if !self.cachedir::exists() self.cachedir::mkdirs() end if !(self.cachedir::exists()) raise Exception,("Variable folder \"" + self.cachedir::toString().to_s) + "\" does not exist and can\'t be automatically created. Please create it with write permissions." end end |
Instance Attribute Details
#cachedir ⇒ Object
Returns the value of attribute cachedir.
10 11 12 |
# File 'lib/com/wiris/util/sys/StoreCache.rb', line 10 def cachedir @cachedir end |
Instance Method Details
#delete(key) ⇒ Object
55 56 57 |
# File 'lib/com/wiris/util/sys/StoreCache.rb', line 55 def delete(key) self.getItemStore(key)::delete() end |
#deleteAll ⇒ Object
37 38 39 |
# File 'lib/com/wiris/util/sys/StoreCache.rb', line 37 def deleteAll() self.deleteStorageDir(self.cachedir) end |
#deleteStorageDir(s) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/com/wiris/util/sys/StoreCache.rb', line 40 def deleteStorageDir(s) if s::exists() && s::isDirectory() files = s::list() for i in 0..files::length - 1 if !((files[i] == ".") || (files[i] == "..")) f = Storage::newStorageWithParent(s,files[i]) if f::isDirectory() deleteStorageDir(f) end f::delete() end i+=1 end end end |
#get(key) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/com/wiris/util/sys/StoreCache.rb', line 27 def get(key) s = self.getItemStore(key) if s::exists() begin return Bytes::ofData(s::readBinary()) end else return nil end end |
#getItemStore(key) ⇒ Object
58 59 60 |
# File 'lib/com/wiris/util/sys/StoreCache.rb', line 58 def getItemStore(key) return Storage::newStorageWithParent(self.cachedir,key) end |
#set(key, value) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/com/wiris/util/sys/StoreCache.rb', line 21 def set(key, value) s = self.getItemStore(key) begin s::writeBinary(value::getData()) end end |