@@ -153,7 +153,7 @@ async def test_prepare_10_stmt_lru(self):
153153
154154 stmts = []
155155 for i in range (iter_max ):
156- s = await self .con .prepare (query .format (i ))
156+ s = await self .con ._prepare (query .format (i ), use_cache = True )
157157 self .assertEqual (await s .fetchval (), i )
158158 stmts .append (s )
159159
@@ -207,7 +207,7 @@ async def test_prepare_11_stmt_gc(self):
207207 # The prepared statement that we'll create will be GCed
208208 # right await. However, its state should be still in
209209 # in the statements LRU cache.
210- await self .con .prepare ('select 1' )
210+ await self .con ._prepare ('select 1' , use_cache = True )
211211 gc .collect ()
212212
213213 self .assertEqual (len (cache ), 1 )
@@ -224,12 +224,12 @@ async def test_prepare_12_stmt_gc(self):
224224 self .assertEqual (len (cache ), 0 )
225225 self .assertEqual (len (self .con ._stmts_to_close ), 0 )
226226
227- stmt = await self .con .prepare ('select 100000000' )
227+ stmt = await self .con ._prepare ('select 100000000' , use_cache = True )
228228 self .assertEqual (len (cache ), 1 )
229229 self .assertEqual (len (self .con ._stmts_to_close ), 0 )
230230
231231 for i in range (cache_max ):
232- await self .con .prepare ('select {}' .format (i ))
232+ await self .con ._prepare ('select {}' .format (i ), use_cache = True )
233233
234234 self .assertEqual (len (cache ), cache_max )
235235 self .assertEqual (len (self .con ._stmts_to_close ), 0 )
@@ -293,7 +293,7 @@ async def test_prepare_15_stmt_gc_cache_disabled(self):
293293 # Disable cache
294294 cache .set_max_size (0 )
295295
296- stmt = await self .con .prepare ('select 100000000' )
296+ stmt = await self .con ._prepare ('select 100000000' , use_cache = True )
297297 self .assertEqual (len (cache ), 0 )
298298 self .assertEqual (len (self .con ._stmts_to_close ), 0 )
299299
@@ -305,7 +305,7 @@ async def test_prepare_15_stmt_gc_cache_disabled(self):
305305 self .assertEqual (len (self .con ._stmts_to_close ), 1 )
306306
307307 # Next "prepare" call will trigger a cleanup
308- stmt = await self .con .prepare ('select 1' )
308+ stmt = await self .con ._prepare ('select 1' , use_cache = True )
309309 self .assertEqual (len (cache ), 0 )
310310 self .assertEqual (len (self .con ._stmts_to_close ), 0 )
311311
@@ -468,25 +468,25 @@ async def test_prepare_24_max_lifetime(self):
468468 self .assertEqual (cache .get_max_lifetime (), 142 )
469469 cache .set_max_lifetime (1 )
470470
471- s = await self .con .prepare ('SELECT 1' )
471+ s = await self .con ._prepare ('SELECT 1' , use_cache = True )
472472 state = s ._state
473473
474- s = await self .con .prepare ('SELECT 1' )
474+ s = await self .con ._prepare ('SELECT 1' , use_cache = True )
475475 self .assertIs (s ._state , state )
476476
477- s = await self .con .prepare ('SELECT 1' )
477+ s = await self .con ._prepare ('SELECT 1' , use_cache = True )
478478 self .assertIs (s ._state , state )
479479
480480 await asyncio .sleep (1 , loop = self .loop )
481481
482- s = await self .con .prepare ('SELECT 1' )
482+ s = await self .con ._prepare ('SELECT 1' , use_cache = True )
483483 self .assertIsNot (s ._state , state )
484484
485485 @tb .with_connection_options (max_cached_statement_lifetime = 0.5 )
486486 async def test_prepare_25_max_lifetime_reset (self ):
487487 cache = self .con ._stmt_cache
488488
489- s = await self .con .prepare ('SELECT 1' )
489+ s = await self .con ._prepare ('SELECT 1' , use_cache = True )
490490 state = s ._state
491491
492492 # Disable max_lifetime
@@ -495,20 +495,20 @@ async def test_prepare_25_max_lifetime_reset(self):
495495 await asyncio .sleep (1 , loop = self .loop )
496496
497497 # The statement should still be cached (as we disabled the timeout).
498- s = await self .con .prepare ('SELECT 1' )
498+ s = await self .con ._prepare ('SELECT 1' , use_cache = True )
499499 self .assertIs (s ._state , state )
500500
501501 @tb .with_connection_options (max_cached_statement_lifetime = 0.5 )
502502 async def test_prepare_26_max_lifetime_max_size (self ):
503503 cache = self .con ._stmt_cache
504504
505- s = await self .con .prepare ('SELECT 1' )
505+ s = await self .con ._prepare ('SELECT 1' , use_cache = True )
506506 state = s ._state
507507
508508 # Disable max_lifetime
509509 cache .set_max_size (0 )
510510
511- s = await self .con .prepare ('SELECT 1' )
511+ s = await self .con ._prepare ('SELECT 1' , use_cache = True )
512512 self .assertIsNot (s ._state , state )
513513
514514 # Check that nothing crashes after the initial timeout
@@ -518,12 +518,12 @@ async def test_prepare_26_max_lifetime_max_size(self):
518518 async def test_prepare_27_max_cacheable_statement_size (self ):
519519 cache = self .con ._stmt_cache
520520
521- await self .con .prepare ('SELECT 1' )
521+ await self .con ._prepare ('SELECT 1' , use_cache = True )
522522 self .assertEqual (len (cache ), 1 )
523523
524524 # Test that long and explicitly created prepared statements
525525 # are not cached.
526- await self .con .prepare ("SELECT \' " + "a" * 50 + "\' " )
526+ await self .con ._prepare ("SELECT \' " + "a" * 50 + "\' " , use_cache = True )
527527 self .assertEqual (len (cache ), 1 )
528528
529529 # Test that implicitly created long prepared statements
@@ -532,7 +532,7 @@ async def test_prepare_27_max_cacheable_statement_size(self):
532532 self .assertEqual (len (cache ), 1 )
533533
534534 # Test that short prepared statements can still be cached.
535- await self .con .prepare ('SELECT 2' )
535+ await self .con ._prepare ('SELECT 2' , use_cache = True )
536536 self .assertEqual (len (cache ), 2 )
537537
538538 async def test_prepare_28_max_args (self ):
@@ -593,3 +593,10 @@ async def test_prepare_31_pgbouncer_note(self):
593593 self .assertTrue ('pgbouncer' in e .hint )
594594 else :
595595 self .fail ('InvalidSQLStatementNameError not raised' )
596+
597+ async def test_prepare_does_not_use_cache (self ):
598+ cache = self .con ._stmt_cache
599+
600+ # prepare with disabled cache
601+ await self .con .prepare ('select 1' )
602+ self .assertEqual (len (cache ), 0 )
0 commit comments