Closed jpemberthy closed 10 years ago
You need to keep the prepared statement object around yourself. The prepared statement object will know which connections it has been prepared on (which is initially all, but there is some extra work around when new connections are opened), and you don't have to do anything to make sure its prepared on all connections.
Don't call #prepare
multiple times with the same CQL. It's wasteful both in that it will require a roundrip to the server, and the way prepared statements are implemented they will stay around for as long as the connection is open.
In the future something like what you describe may be implemented to avoid people shooting themselves in the foot by using #prepare
too much, but it will be transparent to the user. Variations of this question have come up enough times the last few weeks that I think it's time to do something about it, see #104.
@iconara thanks for the clarification =). I'm closing this question.
@iconara Agree that it might be nice for cql-rb to handle this. For now, it'd be nice to have something in the README explaining that you need to do your own statement caching.
Hey guys, when I add a prepared statement is that gonna be cached by the client? or should I handle this? In other words, if I call
client.prepare
with the same cql value will the client know the prepared statement exists on open connections? thanks.