class WirisPlugin::StoreCache

Attributes

cachedir[RW]

Public Class Methods

new(cachedir) click to toggle source
Calls superclass method
# 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

Public Instance Methods

delete(key) click to toggle source
# File lib/com/wiris/util/sys/StoreCache.rb, line 55
def delete(key)
    self.getItemStore(key)::delete()
end
deleteAll() click to toggle source
# File lib/com/wiris/util/sys/StoreCache.rb, line 37
def deleteAll()
    self.deleteStorageDir(self.cachedir)
end
deleteStorageDir(s) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/com/wiris/util/sys/StoreCache.rb, line 58
def getItemStore(key)
    return Storage::newStorageWithParent(self.cachedir,key)
end
set(key, value) click to toggle source
# 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