query cache on the server side
would be great to have query cache on the server side so static data doesnt cause billing increase
52 Replies
Could you say more out this? like if your server functions fetch("http://weather.gov") repeatedly, you want that cached?
hey, no
I don't understand what a query cache is
i have items in the database. i dont wan to fetch them every request
you want these cached between requests?
yes
for speed? cost?
well mostly cost.
What do you mean by static here
this datatable doesnt change
it has always static data
if it never changes it maybe shouldn't be in the database?
well fine to put there, but what's an example of when this would happen?
well it should be in database because it should be possible to change it by admin
add new items for example
and when does that invalidate
that sounds like normal database data then
well this is database data that nearly neve changes and would be great to have cache for it
that can be invalidated
ok that makes sense in some systems, in COnvex that's just already how the databse works
the database is just about as efficient as any cache we'd build, it's right there
in Convex your functions run "inside the database"
well those calls still affect the limits as far i know
ah yeah all of this affects limits
ok i understand
if you have a specific use case I'd love to hear, often writing something with Convex will change this somewhat
You can embed a little data in your function code, that's a bit like what you want
this would be great to generate static code based on item ids then when convex is deployed. but probably asking too much here 🙂
right now i have always to look for item by name / id
I think you should try building this using the database, then if you have performance issues that's the thing to talk about
I think you're looking for a solution that was useful to you in a different environment, a traditional backend where your code runs far from your database
this would be great to generate static code based on item ids then when convex is deployed. but probably asking too much here 🙂I don't quite follow here
performance will depend on user amount. because functions execute every 3 seconds sometimes per user than means 1 millions users could hit all limits very quick
send me an email laying out your architecture concerns here, it's hard when it's theoretical and there are some real use cases that are difficult, but we find they come up rarely
tom@convex.dev
it sounds like you've built things before and run into limits, I'm curious if you'll have those same issues on COnvex
here is example of my code. and function like hasEnoughCoins is requested every time. so would be great to have itemid - name mapping
ah you could just put this in your code yeah?
you mean itemid - name mapping? yes. but its manual work
I'm not following, manual work? Either you have to (manually? or write a script) add them all to the database, or you have to (manually? or write a script) add them to your code
structure like this would have to be maintained
for every item
its fine if those are not much items. but if it s a game those are a lot of items
like how many megabytes?
right now its not big. its not megabytes for sure
anyway i will go with code mapping solution for now 🙂
In convex your options are
- embed the data in your code: keep your code under a few MB and you're fine
- store it in the database: the database is very fast to access from Convex functions
- store it in Convex file storage or an external file storage, you'll have to download it each time you need it, slow
yes just was looking for way to reduce amount of calls to the database
if it's less than a few kilobytes then stick it in your code, I think esbuild will bundle .txt files and .json files too so you don't have to write it out as TypeScript
ok thanks
or really if it's less than a MB or two
generate the JSON from your source of truth and import that in your code
right now its not big. just looking for future where its larger
if it doesn't change quickly, embedding data in your code is the cache you're looking for
bundlers like esbuild (what Convex uses) do a good job letting you include lots of things in the bundle
yes so writing a script that would generate embedding data based on convex database
oh it's already in the DB?
yes its already in convex table
hm I see you're really just trying to save on costs
yeah this works then
consider building it the easy way first and checking how your costs are doing, there's a lot of optimizing too early you can do — but if you've built things like this before and have a good guess at the limits you'll hit, sounds good
consider adding something like this out of the box to convex maybe in future. to pregenerate embedding data based on database tables. i see a lot of apps would need something like this for example app for configuration
Generally I'd prefer to make using the database cheap and fast; it really is faster than you think!
yes sure
thanks for help
btw i mage solidjs work with convex by porting react code. do you have any use for it?
the only thing. i had to make ugly imports from npm module because it did not provide exports for some types
We've heard of a few of these wrappers, definitely interested in this existing!
@convex_dev_module is convex auth?
yes
cool, wanna open an issue on https://github.com/get-convex/convex-auth about us exporting those types?
probably no reason not to
but this code is working currently by integrating it directly into project code
thanks
ah well eventually it'd be great to a library for it! otherwise if it's open source, posting it to e.g. #show-and-tell would be cool
(and even if it's not open source, still very cool to post! But re Solid, if it's open it'd be cool to point people toward this)
GitHub
expose SignInAction and SignOutAction for export · Issue #132 · ge...
Currently, the SignInAction and SignOutAction types need to be imported from the internal implementation path: ./node_modules/@convex-dev/auth/src/server/implementation/index.js This is problematic...
ok i will post source code of solidjs plugin later