Comments (3)
@aiocache.cached(
aiocache.SimpleMemoryCache(serializer=MsgPackSerializer()),
key_builder=custom_key_builder,
)
As I suspected, you're passing a SimpleMemoryCache as the ttl argument. The examples/documentation all say to use kwargs to configure the decorator. This will likely be tightened up to disallow positional arguments in v1.
from aiocache.
Some code to reproduce would help. With no context, it looks like you've managed to set ttl to a SimpleMemoryCache.
from aiocache.
# this would work like asyncio.gather for execute all the methods
# each method call will make requests using run_boto3_fun
for finding, finding_methods in CHECKS:
if finding not in finding_checks:
continue
log_blocking("info", "Executing %s methods", finding.name)
vulnerabilities = [method(credentials) for method in finding_methods]
# this would work like asyncio.gather for execute all the methods
# each method call will make requests using run_boto3_fun
results += list(
collapse(
await collect(vulnerabilities, workers=CPU_CORES),
base_type=Vulnerability,
)
)
# here is the method that going to use the decorator
def custom_key_builder(_func: Any, *args: Any, **kwargs: Any) -> str:
input_data = (args, kwargs)
input_json = json.dumps(input_data, sort_keys=True)
hash_generator = hashlib.sha256()
hash_generator.update(input_json.encode("utf-8"))
hash_value = hash_generator.hexdigest()
custom_key = f"{hash_value}"
return custom_key
@aiocache.cached(
aiocache.SimpleMemoryCache(serializer=MsgPackSerializer()),
key_builder=custom_key_builder,
)
async def run_boto3_fun(
credentials: AwsCredentials,
service: str,
function: str,
parameters: dict[str, object] | None = None,
accepted_error_codes: set[str] | None = None,
) -> dict[str, dict | list]:
try:
session = aioboto3.Session(
aws_access_key_id=credentials.access_key_id,
aws_secret_access_key=credentials.secret_access_key,
aws_session_token=credentials.session_token,
)
async with session.client(service) as client:
return await getattr(client, function)(**(parameters or {}))
except botocore.exceptions.ClientError as error:
return {}
from aiocache.
Related Issues (20)
- BaseCache should be ABC HOT 2
- Remove factory
- Tests folder being imported when installing version 0.12.0 HOT 1
- Merge cache implementation classes for each backend
- Library is unusable with redis older than 4.2.0 installed, even if redis isn't used HOT 2
- Type issues with VS Code + aiocache HOT 1
- Make it possible to run tests with a subset of dependencies HOT 5
- Cache key based on "self" in @cached decorator might not always be unique HOT 1
- [Question] Reuse decorator settings + Race Conditions
- "No module named 'redis.asyncio'" when trying to build with docker HOT 1
- Passing username to Redis in decorators HOT 1
- Redis cache decorator fail on Python3.11 HOT 2
- Create Multiple caches HOT 3
- New release HOT 1
- Preserve function signature with decorator HOT 3
- set_cache default does not work with plugins HOT 2
- UnicodeDecodeError when using MsgPackSerializer HOT 7
- Error -2 connecting to redis server docker HOT 1
- Caching mutable function outputs HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiocache.