Class: Proj::GridCache

Inherits:
Object
  • Object
show all
Defined in:
lib/proj/grid_cache.rb

Overview

To avoid repeated network access, it is possible to enable a local cache of grids. Grid data is stored in a SQLite3 database, cache.db, that is by default stored stored in the PROJ user writable directory.

The local cache is enabled by default with a size of 300MB. Cache settings can be overridden by this class, env variables or the proj.ini file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ GridCache

Returns a new instance of GridCache.



13
14
15
# File 'lib/proj/grid_cache.rb', line 13

def initialize(context)
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



11
12
13
# File 'lib/proj/grid_cache.rb', line 11

def context
  @context
end

Instance Method Details

#clearObject

Clears the cache



60
61
62
# File 'lib/proj/grid_cache.rb', line 60

def clear
  Api.proj_grid_cache_clear(self.context)
end

#enabled=(value) ⇒ Object

Enables or disables the grid cache



22
23
24
# File 'lib/proj/grid_cache.rb', line 22

def enabled=(value)
  Api.proj_grid_cache_set_enable(self.context, value ? 1 : 0)
end

#max_size=(value) ⇒ Object

Sets the cache size

Parameters:

  • value (Integer)

    Maximum size in Megabytes (1024*1024 bytes), or negative value to set unlimited size.

See Also:



42
43
44
45
# File 'lib/proj/grid_cache.rb', line 42

def max_size=(value)
  Api.proj_grid_cache_set_max_size(self.context, value)
  value
end

#path=(value) ⇒ Object

Set the path and file of the local cache file which is sqlite database. By default it is stored in the user writable directory.

Parameters:

  • value (String)
    • Full path to the cache. If set to nil then caching will be disabled.

See Also:



32
33
34
35
# File 'lib/proj/grid_cache.rb', line 32

def path=(value)
  Api.proj_grid_cache_set_filename(self.context, value.encode('UTF-8'))
  value
end

#ttl=(value) ⇒ Object

Specifies the time-to-live delay for re-checking if the cached properties of files are still up-to-date.

Parameters:

  • value (Integer)

    Delay in seconds. Use negative value for no expiration.

See Also:



52
53
54
55
# File 'lib/proj/grid_cache.rb', line 52

def ttl=(value)
  Api.proj_grid_cache_set_ttl(self.context, value)
  value
end