File Cache
FileCache
Bases: CacheStrategy
Cache data as file.
We store the cached files in a separate folder in the CKAN storage.
generate_unique_consistent_filename(key)
Generate unique and consistent filename based on the key.
PARAMETER | DESCRIPTION |
---|---|
key
|
The cache key to generate the filename.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The filename. |
get_data(key)
Return data from cache if exists.
PARAMETER | DESCRIPTION |
---|---|
key
|
The cache key to retrieve the data.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame | None
|
The data if exists, otherwise None. |
invalidate(key)
Remove data from cache.
PARAMETER | DESCRIPTION |
---|---|
key
|
The cache key to invalidate.
TYPE:
|
is_file_cache_expired(file_path)
staticmethod
Check if file cache is expired.
If TTL is 0 then cache never expires.
PARAMETER | DESCRIPTION |
---|---|
file_path
|
The path to the file.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
True if file cache is expired, otherwise False. |
make_file_path_from_key(key)
Generate file path based on the key
PARAMETER | DESCRIPTION |
---|---|
key
|
The cache key to generate the file path.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The file path. |
read_data(file)
abstractmethod
Read cached data from a file object.
PARAMETER | DESCRIPTION |
---|---|
file
|
The file object to read the data.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame | None
|
The data if exists, otherwise None. |
set_data(key, data)
Store data to cache.
PARAMETER | DESCRIPTION |
---|---|
key
|
The cache key to store the data.
TYPE:
|
data
|
The data to be stored.
TYPE:
|
write_data(file_path, data)
abstractmethod
Defines how to write data to a file.
PARAMETER | DESCRIPTION |
---|---|
file_path
|
The path to the file.
TYPE:
|
data
|
The data to be stored.
TYPE:
|
FileCacheORC
Bases: FileCache
Cache data as ORC file
read_data(file)
Read cached data from an ORC file.
PARAMETER | DESCRIPTION |
---|---|
file
|
The file object to read the data.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame | None
|
The data if exists, otherwise None. |
write_data(file_path, data)
Write data to an ORC file.
PARAMETER | DESCRIPTION |
---|---|
file_path
|
The path to the file.
TYPE:
|
data
|
The data to be stored.
TYPE:
|
FileCacheCSV
Bases: FileCache
Cache data as CSV file
read_data(file)
Read cached data from a CSV file.
PARAMETER | DESCRIPTION |
---|---|
file
|
The file object to read the data.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame | None
|
The data if exists, otherwise None. |
write_data(file_path, data)
Write data to a CSV file.
PARAMETER | DESCRIPTION |
---|---|
file_path
|
The path to the file.
TYPE:
|
data
|
The data to be stored.
TYPE:
|