Skip to main content

pygridgain-dogpile

A dogpile.cache backend that stores entries in GridGain, built on the GridGain 8.x Python thin client.

An application that already uses dogpile can switch its cache to a GridGain cluster by changing only the configuration.

Installation

pip install pygridgain-dogpile

This also installs pygridgain (the 8.x client) and dogpile.cache.

The backend is registered in the dogpile.cache entry point group as gridgain and as dogpile.cache.gridgain, so you do not need to import it.

Minimal example

from dogpile.cache import make_region

region = make_region().configure(
    'gridgain',
    expiration_time=3600,
    arguments={'url': '127.0.0.1:10800'}
)

region.set('greeting', 'Hello, world!')
print(region.get('greeting'))


@region.cache_on_arguments()
def expensive(number):
    return number * number

A full example is in examples/dogpile_cache.py, which is part of the source distribution (pip download --no-binary :all: pygridgain-dogpile).

Configuration arguments

Argument Meaning Default
url Address of a cluster node as 'host:port', several addresses separated by commas, or an iterable of addresses. Write an IPv6 address in brackets: '[::1]:10800'. localhost:10800
cache_name Cache for the entries. It is created on first use if it does not exist. dogpile_cache
backups Number of backups. Used only when the backend creates the cache. 0
gridgain_expiration_time Seconds after which an entry expires on the server. 0 (never)
pool_size Number of clients the backend may open. Each client connects to every node in url. 8
distributed_lock Whether get_mutex returns a lock held in the cluster, not in the process. False
lock_timeout Seconds after which a distributed lock is released, even if its holder did not release it. 0 (never)
client_args Keyword arguments for pygridgain.Client, such as SSL and authentication settings. timeout is in seconds per socket operation. It is 10 by default, so a node that stops answering cannot hang the application. Pass None to block forever. {'timeout': 10}
client An already connected client to use instead of opening connections. Cannot be combined with pool_size. None

You can pass any argument as a string, as oslo.cache does. An unknown argument raises ValueError, so a typo in a configuration file is not ignored.

What is stored

The backend is a BytesBackend: dogpile serializes values, and the cluster stores them as byte arrays. You do not need to register any binary types, and other clients can read the entries as plain bytes. Keys are stored as strings. A region with its own key_mangler also works.

get_multi, set_multi and delete_multi use the cluster's bulk operations, so a request for many keys takes one round trip.

Expiration

A region tracks the age of each value itself. gridgain_expiration_time also sets a TTL on the server, so old entries that the region no longer uses do not take memory.

Set it higher than the region's expiration_time, for example to twice that value. When a value is stale, dogpile lets one caller create a new value and gives the stale value to all other callers in the meantime. This works only while the server still has the stale value. If the two times are equal, all callers wait for the new value. If the TTL is shorter, the region misses earlier than expected.

Reading an entry does not extend its life. dogpile also counts the age of an entry from the time it was created.

The TTL needs cluster support for the ExpiryPolicy API. Without it, the backend raises NotSupportedByClusterError. With the default 0, entries never expire on the server.

Connections and threads

pygridgain.Client is not thread-safe, but all threads of a process share one dogpile region. So the backend keeps a pool of connections and gives one to each operation. Callers wait when all pool_size connections are in use.

Each client in the pool connects to every node in url and sends each single-key request to the node that owns the key. So a process opens up to pool_size sockets per node, and each worker process opens its own sockets. Choose pool_size with this in mind. To use one socket per client, pass client_args={'partition_aware': False}. Single-key requests then take an extra hop inside the cluster.

If you pass your own client, the pool has only this one connection: operations wait for each other, and you must close it yourself.

Locking and the dogpile effect

When a popular entry expires, many threads may try to create it again at the same time. This is the dogpile effect that gives the library its name. dogpile makes these threads wait on a mutex from the backend.

By default the backend returns None, and dogpile uses a threading.Lock. This works within one process, but with several worker processes, each process still creates the value.

With distributed_lock set to True, the lock is held in the cluster. Like dogpile's own memcached lock, it uses put_if_absent. Each lock has a unique token, so a caller cannot release a lock it does not hold.

With lock_timeout, the lock expires by itself, so a holder that dies does not keep the key locked forever. But if creating the value takes longer than the timeout, another thread may start to create the same value. dogpile has the same limitation for memcached. With lock_timeout at 0, the lock never expires, so a holder that never releases it keeps the key locked.

region = make_region().configure(
    'gridgain',
    expiration_time=3600,
    arguments={
        'url': '127.0.0.1:10800',
        'distributed_lock': True,
        'lock_timeout': 60,
    }
)

Use with oslo.cache

oslo.cache wraps dogpile.cache. OpenStack services, such as Keystone, use it to configure caching. The backend works with it (tested with oslo.cache 4.1.1), but you cannot select it with configuration only yet.

oslo.cache checks [cache] backend against a fixed list of names in oslo_cache/_opts.py. Any other name, including dogpile.cache.gridgain, is rejected before dogpile sees it:

ValueError: Valid values are [oslo_cache.memcache_pool, oslo_cache.dict,
..., dogpile.cache.redis, dogpile.cache.memory, dogpile.cache.null],
but found 'gridgain'

So oslo.cache needs a one-line patch that adds the name to this list, as was done for dogpile.cache.redis_sentinel and oslo_cache.etcd3gw. With this patch, everything else works unchanged: region configuration, backend_argument strings, single-key and multi-key operations, the distributed mutex, and get_memoization_decorator, which Keystone uses for caching.

When the name is accepted upstream, the configuration is:

[cache]
enabled = true
backend = dogpile.cache.gridgain
backend_argument = url:127.0.0.1:10800
backend_argument = cache_name:keystone_cache
backend_argument = gridgain_expiration_time:3600

oslo.cache sets the region's expiration_time from [cache] expiration_time, so you only need to set the server TTL here. Keep it above [cache] expiration_time, which is 600 by default.

Running the tests

The tests need a running cluster; they do not start one. GRIDGAIN_ADDRESS sets its address, the default is 127.0.0.1:10800:

docker-compose up -d
pip install -r requirements/tests.txt
pip install -e .
pytest

If no cluster is available, the tests that need one are skipped. Tests of argument parsing and the entry point do not need a cluster and always run.

The cluster restart test also needs a command that restarts the cluster. Without it, the test is skipped. For the node from docker-compose.yml:

GRIDGAIN_RESTART_COMMAND='docker-compose restart gridgain' pytest

License

Copyright (c) 2026 MariaDB plc. Licensed under the MariaDB Software License Terms; see licenses/LICENSE.

Metadata

Release files for pygridgain-dogpile 1.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pygridgain-dogpile 1.7.0
File Size Uploaded Provenance Actions
pygridgain_dogpile-1.7.0.tar.gz 28.4 kB Without provenance Details for pygridgain_dogpile-1.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pygridgain-dogpile 1.7.0
File Interpreter ABI Platform Actions
pygridgain_dogpile-1.7.0-py3-none-any.whl Python 3 none any Details for pygridgain_dogpile-1.7.0-py3-none-any.whl

Total release size: 45.9 kB

Release files / pygridgain_dogpile-1.7.0.tar.gz

Download URL pygridgain_dogpile-1.7.0.tar.gz
Size 28.4 kB
Tags Source
SHA-256 checksum
How to use checksums
fc0caac9957c2f3532a87779cc4b65bc75a5626334b07de8ec93472a9bae603f
BLAKE2b-256 checksum
How to use checksums
60c08b780c424e6707615103e9bb0ba8bf9014260be556e76be1ce26a84a953a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Release files / pygridgain_dogpile-1.7.0-py3-none-any.whl

Download URL pygridgain_dogpile-1.7.0-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
210b1fb15c5988abfe2e94eda7b6800a1d3cd66c7d9dc2801a9601fb179843e8
BLAKE2b-256 checksum
How to use checksums
0848ae216cb6acc6ffb91c8d435ba097f6b23c1f7097d1fbad1c57318e2adbb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.12

Security for pygridgain-dogpile 1.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.7.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page