Observed since 20 Oct, 20:48 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
aerospike-flask-cache
Aerospike cache backend for Flask
Aerospike is a low-latency distributed NoSQL database. This module provides a cache backend for Flask-Caching, the caching extension for Flask.
Questions, comments, feedback? Find me in the #ask-the-community channel in the Aerospike Developer Discord server.
Install the module with the following command:
pip install aerospike_flask_cache
config = {
'DEBUG': True,
'CACHE_TYPE': "aerospike_flask.cache.aerospike.AerospikeCache",
'CACHE_AEROSPIKE_HOSTS': [("172.17.0.2", 3000, None)],
'CACHE_AEROSPIKE_NAMESPACE': "cache"
}
app = Flask(__name__)
app.config.from_mapping(config)
cache = Cache(app)
| Configuration Value | Description |
|---|---|
CACHE_TYPE | aerospike_flask.cache.aerospike.AerospikeCache |
CACHE_DEFAULT_TIMEOUT | The timeout (TTL) that is used if no other timeout is specified. Unit of time is seconds. Defaults to 300. |
CACHE_AEROSPIKE_CLIENT | Instantiated aerospike.client instance. One of CACHE_AEROSPIKE_CLIENT or CACHE_AEROSPIKE_HOSTS must be specified with CACHE_AEROSPIKE_CLIENT taking precedence. |
CACHE_AEROSPIKE_HOSTS | List of tuples of (host, port, tls-name) used to instantiate a aerospike.client object. One of CACHE_AEROSPIKE_CLIENT or CACHE_AEROSPIKE_HOSTS must be specified with CACHE_AEROSPIKE_CLIENT taking precedence. |
CACHE_AEROSPIKE_NAMESPACE | The name of the Aerospike namespace to store cached values. Defaults to "cache". |
CACHE_AEROSPIKE_SET | The name of the Aerospike set to store cached values. Defaults to None (Aerospike "null set"). |
To enable DEBUG level logs for the aerospike_flask.cache module, set the level of the aerospike_flask_cache logger:
from flask.logging import default_handler
logger = logging.getLogger('aerospike_flask_cache')
logger.setLevel(logging.DEBUG)
logger.addHandler(default_handler)
To enable DEBUG level logs for the aerospike.client module, add the default Flask handler to the aerospike module:
from flask.logging import default_handler
import aerospike
aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
aerospike.set_log_handler(default_handler)
To enable DEBUG level logs when running tests use --log-cli-level:
pytest --log-cli-level=DEBUG
Create a virtual environment with the desired version of Python:
python -m venv .venv
source .venv/bin/activate
Install the package as a symbolic link to enable editing of the source code without re-installing the package:
pip install -e .
Print version to verify:
python -c "import aerospike_flask.cache; print(aerospike_flask.cache.__version__)"
The tests are run with a Github Action on push or pull request to dev and main branches. Tests should pass locally first.
The tests are run against a running Aerospike Database server. The host and port of a seed node of the test server are set with environment variables:
export AEROSPIKE_FLASK_CACHE_TEST_DB_HOST="127.0.0.1"
export AEROSPIKE_FLASK_CACHE_TEST_DB_PORT="3000"
pytest
WARNING: Running tests against a live database will truncate the testset set in the cachetest namespace
For local testing you can run Aerospike Database Enterprise in Docker. Aerospike Enterprise comes with a free developer license for single-node configuration which can be used for running tests.
The following command will run Aerospike Database Enterprise using the free developer license in a container listening on port 3999.
docker run -tid --name aerospike-server-pytest -p 3999:3000 \
-v "$(pwd)/tests/opt":/opt/aerospike_flask_cache \
aerospike/aerospike-server-enterprise \
--config-file /opt/aerospike_flask_cache/aerospike.conf
Note: On Linux distributions with SELinux enabled you may need to append the :Z flag to the mount: "$(pwd)/opt":/opt/aerospike_flask_cache:Z
The IP address of the container can be obtained from docker inspect. Set the AEROSPIKE_FLASK_CACHE_TEST_DB_HOST environment variable to this IP address and the port that was mapped in the above Docker command:
export AEROSPIKE_FLASK_CACHE_TEST_DB_HOST="$(docker inspect --format='{{.NetworkSettings.IPAddress}}' aerospike-server-pytest)"
export AEROSPIKE_FLASK_CACHE_TEST_DB_PORT="$(docker inspect --format='{{(index (index .NetworkSettings.Ports "3000/tcp") 0).HostPort}}' aerospike-server-pytest)"
To view test coverage run:
pytest --cov=aerospike_flask.cache tests/ --cov-report term-missing
Source code is checked with a Github Action using the flake8 linter. Run it locally first to ensure any changes will pass:
flake8 src/ --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 src/ --count --exit-zero --max-complexity=10 --max-line-length=80 --statistics
Packages are built with a Github Action on push or pull request into the dev and main branches.
Manually build Python packages (sdist and wheel) using hatch:
hatch build
Packages are published to TestPyPI with a Github Action when pushed or merged into the dev branch.
Packages are published to PyPI with a Github Action when version tags are pushed.
To push a version tag:
VERSION="v$(python -c 'import aerospike_flask.cache; print(aerospike_flask.cache.__version__)')"; git tag -a -m $VERSION $VERSION
git push --tags
By default Aerospike is not configured to run the "namespace supervisor (nsup). To use timeout (eg. CACHE_DEFAULT_TIMEOUT=300) then you ust set nsup-period to a non-zero value in the aerospike.conf file. See nsup-period in the Aerospike documentation.
Failing to do so will result in the following error when using a timeout value other than 0 (never expires):
ERROR Failed to set TTL (timeout=X). Aerospike namespace supervisor (nsup) is disabled. Error 22: AEROSPIKE_ERR_FAIL_FORBIDDEN
Download counts and popularity will appear here as the collector receives them.
| Package / target | Requirement | Relationship |
|---|---|---|
aerospikeEnvironment{
"extras": "",
"marker": null,
"requires_python": "<=3.13,>=3.8",
"evaluation": "NOT_EVALUATED"
} | aerospike | runtime |
flask-cachingEnvironment{
"extras": "",
"marker": null,
"requires_python": "<=3.13,>=3.8",
"evaluation": "NOT_EVALUATED"
} | flask-caching | runtime |
bdist_wheel · 8.64 KB · Python py3
sdist · 12.83 KB · Python source
Observed since 20 Oct, 20:48 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:3a013f5549ce4cbfcc8dfbda7497bca8cce9b296ed28751b33e89c19689cff74