Comments (5)
Here is how we set up the backends:
redis_backend = cache.setup(
redis_url,
client_name=None,
suppress=False,
client_side=False,
middlewares=(add_prefix(f"{build_stamp}:"),),
)
mem_backend = cache.setup(
"mem://?check_interval=10&size=100000", prefix="mem:", suppress=False, enable=enable_in_memory_cache
)
This is how we are using early
Repalced:
@cache(ttl="1h", key=f"mem:{key}")
@cache(ttl="1h", key=key)
With:
@cache.early(ttl="1h", early_ttl="40m", key=f"mem:{key}")
@cache.early(ttl="1h", early_ttl="40m", key=key)
from cashews.
Update: Looks like if we do
mem_backend = cache.setup(
"mem://?check_interval=10&size=100000", prefix="early:v2:mem:", suppress=False, enable=enable_in_memory_cache
)
It works. Looks like this prefix appending causes us to have to remember to add this prefix everywhere. I don't know if this is intended behavior or not.
from cashews.
Seems like we can use set methods along side early caching. Here is a test example:
`foo_key = "foo:{id}"
async def set_foo_by_id():
await cache.set_many(
{("early:v2" + foo_key.format(id=id)): str(id) for id in [1,2,3]},
expire="1h",
)
@cache.early(ttl="1h", early_ttl="40m", key=foo_key, condition=NOT_NONE)
async def get_foo_by_id(id):
return str(id)
await set_foo_by_id()
print(await get_foo_by_id(1))`
Throws error:
/Users/sohanggandhi/fh-repos/fh-mono/prompt_server/.venv/lib/python3.11/site-packages/cashews/de │ prompt-server-online | │ corators/cache/early.py:88 in _wrap │ prompt-server-online | ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ prompt-server-online | ValueError: too many values to unpack (expected 2)
from cashews.
Hello, thanks for reporting
Looks like this prefix appending causes us to have to remember to add this prefix everywhere. I don't know if this is intended behavior or not.
In general, this is how it was intended, but now I understand that it is not very "user friendly". So probably I will fix it somehow. I did this because values in the cache for the regular cache and early stored differently, which can lead to errors
For now I can suggest to remove this prefix by passing empty string (prefix=""
)
@cache.early(ttl="1h", early_ttl="40m", key=f"mem:{key}", prefix="")
@cache.early(ttl="1h", early_ttl="40m", key=key, prefix="")
from cashews.
@Krukov thanks for getting back to us. We already tried as you suggest but even with prefix="", the prefix "v2:" is still added. So doesn't fix the issue.
from cashews.
Related Issues (20)
- 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 9
- 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 2
- Feature: Get or set HOT 1
- _empty and _empty_in_redis marker objects leak HOT 1
- Redis Client Side Connection Timeout HOT 7
- Interrupted `StreamingResponse` will cache partial response HOT 3
- The `add_prefix` middleware didn't consider `delete_many` HOT 1
- Problem with codecov
- valkeys backend HOT 1
- TypeError: cannot pickle 'coroutine' object when using async def as default argument in get_or_set 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.