semvec/pypi-packages huggingface dataset:
mutexcache 0.1.1
Dynamically created, cached mutexes in Python.
License: MIT

# mutexcache-python

A small utility library for dynamically creating mutexes based on cache keys. 

## Use case

Say you're implementing a graphql server, with object fields which asynchronously resolve independently of each other. 
Multiple fields perform the same operation, and thus should use a mutex and some basic caching to ensure that the 
database query happens at most once. If you have an array of these objects, suddenly they're all using the same mutex,
which can degrade performance. 

Instead of using one mutex to rule them all, dynamically create multiple short-lived mutexes which each object can use 
independently of other resolving objects. By using the same cache key for the mutexes as you would for your cache check,
you can almost transparently use dynamically created mutexes without worrying about performance or allocation/deallocation
of mutexes. 

With mutexcache, if a mutex associated with a cache key is already stored, then it will be returned. Otherwise, a new 
mutex will silently be created, stored for future use, and returned. 

## Installation

`pip3 install mutexcache`

## Usage

MutexCache.get() returns `threading.Lock` objects.

```python
from mutexcache import MutexCache

mutex_cache = MutexCache() # optionally, provide a ttl in seconds 

cache_key_a = "key_a"
cache_key_b = "key_b"

mut_a = mutex_cache.get(cache_key_a)
mut_b = mutex_cache.get(cache_key_b)

# [...do stuff with your Locks...]
```
microstate 0.2.0
Experimental standalone state storage service for crawlers at www.microprediction.org
License: MIT

# microstate 

Simple REST state storage tied to a write key

### You need a key 

    from microstate import MicroStateWriter
    write_key = MicroStateWriter.create_key(difficulty=11) # Takes a while! 
   
to instantiate a writer
    
    writer = MicroStateWriter(write_key=write_key)

### Usage pattern 1

Assume we have data taking the form of a dictionary

    data = {'age':17,'model':'my model','params':{'mean':17,'std':10}
    
Store data: 

    writer.set(value=data)
    
Retrieve data:

    data = writer.get()     
    
### Usage pattern 2 (using a logical memory location from 0 to 99)

Store data with a location index

    writer.set(value=data, k=34)
    
Retrieve data with a location index

    data = writer.get(k=34) 
    
### Other data types (caution!)

- Tuples will be converted to lists
- int, float to string

To preserve types use dict or list 

### Partial support for tuple

Tuples can be stored but will be converted to list. 
    
### Memory limits 

Assuming a write key of difficulty at least 11:

    location  0      holds    320 kb
    locations 1-319  hold       1 kb each