knowhere
In memory cache, a python implementation of zizou with a different expiration policy
Features
- Store millions of entries
- High concurrent thread-safe access
- Expiration support
- Shard support to avoid locks on whole db during any concurrent read/writes/deletes
Installation
pip install knowhere
Usage
Initialize
shard_size should be a power of 2. This size must be set according to the number of keys you expect to be there in the cache at any given time.
from datetime import timedelta
from decimal import Decimal
import uuid, time, json, sys, knowhere
c = knowhere.Cache(shard_size=2, eviction_interval=timedelta(seconds=10))
Set
c.set("key", "value", ttl=timedelta(seconds=5))
Default expiry will be set to 5 minutes if no ttl is specified
Get
c.get("key")
Delete
c.delete("key")
Flush
deletes all keys in the cache
c.flush()
Info
gives all shards and number of keys in each shard as a json
c.info()
Keys
gives a list of all keys in the cache
c.keys()
Expiration policy
knowhere expires keys the same way redis does. You can find it here. Specifically, this is what knowhere does on every eviction interval for each shard
- Step 1: Get 20 random keys from the shard
- Step 2: Delete all the keys which should be expired.
- Step 3: If more than 4 of the 20 keys were expired, start again from step 1
Metadata
Release files for knowhere 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| knowhere-1.0.0.tar.gz | 3.3 kB | Details |
Release files / knowhere-1.0.0.tar.gz
| Download URL | knowhere-1.0.0.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5b897b0265428c61f619ba04a27b65a4a8b807beedb8e08b5d8e69829b2e8f2f
|
|
BLAKE2b-256 checksum How to use checksums |
5458da4de0ec55f0f78f49f5e4b45782cd717ccd4f26f98ba6864e382eb0c818
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.12
|