Comments (7)
Thanks for all your suggestions and contribution
We need to check repr because we it will raise an error if structure of object have been changed. As we use pickle we can have some strange errors with cache - for example we have structure with some fields and we store it in cache
@dataclasses.dataclass
class Schema:
name: str
async def func():
await cache.set("key", Schema("test"))
Than we change the schema
@dataclasses.dataclass
class Schema:
first_name: str
last_name: str
And without checking repl we will have an error
async def func():
a = await cache.get("key")
print(a.first_name)
>>> AttributeError: 'Schema' object has no attribute 'first_name'
https://github.com/Krukov/cashews#cache-invalidation-on-code-change
Regarding mget
, I prefer to return immutable structures. I think a list comprehension in this case looks too heavy and hard to maintain and troubleshoot.
from cashews.
@AIGeneratedUsername Can I ask you for review this PR ?
from cashews.
Yep, thank to point it. I hope that is no doubts about socket_keepalive
- the same setting we have in our browsers in it set to true
.
To be honest there is no reason why socket_timeout
is exactly 0.1 by default. I just want to set it with a small amount based on my experience. We had an issues with cache when it stacked and we got the whole app down by the end just because timeout had a big value or didn't set. I don't think that we can count the value for socket timeout, but for cache it should be extremely small just because of the purpose of cache.
I saw some redis benchmarks and they said that average response time is 200 us ( 0.0002 sec) ! and 100 percentile took less then 3 ms ( 0.003 sec) (https://redis.io/topics/benchmarks) !
Do you have some suggestions for that value?
from cashews.
@Krukov Could you please clarify the purpose of checking __repr__
of unpickled data?
if self._check_repr:
repr(value)
It will be great to have a comment in the code for such not obvious things.
Why do you convert to tuple
? This seems to be redundant because mget
returns a list.
async def get_many(self, *keys):
values = []
for key, value in zip(keys, await super().get_many(*keys) or [None] * len(keys)):
values.append(await self._get_value(value, key))
return tuple(values)
By the way, we can write a list comprehension instead:
return [await self._get_value(value, key) for key, value in zip(keys, await super().get_many(*keys) or [None] * len(keys))]
from cashews.
Regarding the code changes:
- we support aioredis 1.3.x and it have this strange mget signature https://aioredis.readthedocs.io/en/v1.3.0/mixins.html#aioredis.commands.StringCommandsMixin.mget
- good point
- I don't think that is bad , we just hide converting from seconds to millisecond because you can't use floating seconds with
ex
arg ofset
cmd with redis (https://redis.io/commands/set)
await cache.set("key", "value", expire=10) # will set ttl to 10 seconds with redis cmd "SET key value EX 10"
await cache.set("key", "value", expire=10.0) # will also set ttl to 10 seconds "SET key value PX 10000"
- I don't remember why I did it but you right
- Thanks
from cashews.
By the way, it may be great to find how to make type hinting to be IDE-friendly.
Perhaps the only way is to add type hints everywhere, but it is too much work to do from the scratch for the whole package.
from cashews.
@Krukov Could you please let know in a few words what is the background behind:
kwargs.setdefault("socket_keepalive", True)
kwargs.setdefault("socket_timeout", 0.1)
Why are exactly these values used? Why timeout is 0.1 and not 0.2, or 0.3, etc.
So if someone will decide to contribute, everybody will be on the same page about specific decisions under the hood.
I know the settings definition, but I am not sure about choosing the best values. I do not mean that the current values are bad or wrong.
from cashews.
Related Issues (20)
- Support for non async code ( synchronous )
- CacheEtagMiddleware breaks with redis client_side cache HOT 1
- Counter in Cache condition
- cache_control_ttl is undocumented HOT 1
- Documenting with sphinx? HOT 1
- ValueError: Duplicated timeseries in CollectorRegistry HOT 2
- early_ttl not working in combination with CacheEtagMiddleware HOT 5
- Gracefully close a connection pool with redis > 5.0.1
- Cannot close Redis connection - AttributeError: 'Redis' object has no attribute '_client' HOT 4
- Cache doesn't work with GZIPMiddleware HOT 5
- JSON serializer HOT 5
- Early cache with sqlalchemy & fastapi depend (sqlalchemy.exc.IllegalStateChangeError: Method 'close()' can't be called here; method '_connection_for_bind()' is already in progress and this would cause an unexpected state change to <SessionTransactionState.CLOSED: 5>) HOT 1
- Formatter Called with Formatted Value HOT 6
- CacheRequestControlMiddleware: Backend not found exception with non-default cache prefix HOT 3
- cache_control_ttl can't be used directly with cache api HOT 1
- thunder_protection with multiple event loops breaks HOT 3
- re.error: bad character in group name when using custom formatter in a tag HOT 3
- Unhandled exception when there are only backends with prefixes HOT 1
- Feature: Get or set
- _empty and _empty_in_redis marker objects leak HOT 1
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 cashews.