Skip to content

Commit 05ce0e4

Browse files
author
Erlend E. Aasland
committed
Address review: don't expose cache API
1 parent 2795aca commit 05ce0e4

File tree

6 files changed

+3
-84
lines changed

6 files changed

+3
-84
lines changed

Doc/library/sqlite3.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -515,16 +515,6 @@ Connection Objects
515515

516516
.. XXX what's a db_row-based solution?
517517
518-
.. method:: statement_cache()
519-
520-
Returns the LRU statement cache for this connection. The statement
521-
cache is implemented using :meth:`functools.lru_cache`, so it's
522-
possible to inspect its state by calling :func:`~functools.cache_info`
523-
or :func:`~functools.cache_parameters` on the returned object. The
524-
cache can be cleared by calling :func:`~functools.cache_clear` on
525-
the returned object.
526-
527-
.. versionadded:: 3.10
528518
529519
.. attribute:: text_factory
530520

Doc/whatsnew/3.11.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,6 @@ New Modules
8686
Improved Modules
8787
================
8888

89-
sqlite3
90-
-------
91-
92-
:mod:`sqlite3` now utilizes :meth:`functools.lru_cache` to implement the
93-
connection statement cache. The statement cache can be accessed via the new
94-
method :meth:`sqlite3.Connection.statement_cache`. As a small optimisation, the
95-
default statement cache size has been increased from 100 to 128.
96-
(Contributed by Erlend E. Aasland in :issue:`42862`.)
97-
9889

9990
Optimizations
10091
=============

Lib/sqlite3/test/dbapi.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -197,33 +197,6 @@ def test_open_uri(self):
197197
gc_collect()
198198

199199

200-
class StatementCacheTests(unittest.TestCase):
201-
def test_statement_cache(self):
202-
query = 'select * from sqlite_master'
203-
cx = sqlite.connect(':memory:')
204-
cx.execute(query) # cache miss
205-
cx.execute(query) # cache hit
206-
cache = cx.statement_cache()
207-
info = cache.cache_info()
208-
self.assertEqual(info.hits, 1)
209-
self.assertEqual(info.misses, 1)
210-
self.assertEqual(info.maxsize, 128)
211-
self.assertEqual(info.currsize, 1)
212-
213-
def test_statement_cache_maxsize(self):
214-
maxsize = 8
215-
testsize = maxsize + 1
216-
cx = sqlite.connect(':memory:', cached_statements=maxsize)
217-
for i in range(testsize):
218-
cx.execute(f'select {i}')
219-
cache = cx.statement_cache()
220-
info = cache.cache_info()
221-
self.assertEqual(info.hits, 0)
222-
self.assertEqual(info.misses, testsize)
223-
self.assertEqual(info.maxsize, maxsize)
224-
self.assertEqual(info.currsize, maxsize)
225-
226-
227200
class CursorTests(unittest.TestCase):
228201
def setUp(self):
229202
self.cx = sqlite.connect(":memory:")
@@ -975,7 +948,6 @@ def suite():
975948
ExtensionTests,
976949
ModuleTests,
977950
SqliteOnConflictTests,
978-
StatementCacheTests,
979951
ThreadTests,
980952
]
981953
return unittest.TestSuite(
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
:mod:`sqlite3` now utilizes :meth:`functools.lru_cache` to implement the
2-
connection statement cache. The statement cache can be accessed via the new
3-
method :meth:`sqlite3.Connection.statement_cache`. As a small optimisation, the
4-
default statement cache size has been increased from 100 to 128.
2+
connection statement cache. As a small optimisation, the default
3+
statement cache size has been increased from 100 to 128.
54
Patch by Erlend E. Aasland.

Modules/_sqlite/clinic/connection.c.h

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,6 @@
22
preserve
33
[clinic start generated code]*/
44

5-
PyDoc_STRVAR(pysqlite_connection_statement_cache__doc__,
6-
"statement_cache($self, /)\n"
7-
"--\n"
8-
"\n"
9-
"Return the connection statement cache.");
10-
11-
#define PYSQLITE_CONNECTION_STATEMENT_CACHE_METHODDEF \
12-
{"statement_cache", (PyCFunction)pysqlite_connection_statement_cache, METH_NOARGS, pysqlite_connection_statement_cache__doc__},
13-
14-
static PyObject *
15-
pysqlite_connection_statement_cache_impl(pysqlite_Connection *self);
16-
17-
static PyObject *
18-
pysqlite_connection_statement_cache(pysqlite_Connection *self, PyObject *Py_UNUSED(ignored))
19-
{
20-
return pysqlite_connection_statement_cache_impl(self);
21-
}
22-
235
PyDoc_STRVAR(pysqlite_connection_cursor__doc__,
246
"cursor($self, /, factory=<unrepresentable>)\n"
257
"--\n"
@@ -728,4 +710,4 @@ pysqlite_connection_exit(pysqlite_Connection *self, PyObject *const *args, Py_ss
728710
#ifndef PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
729711
#define PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF
730712
#endif /* !defined(PYSQLITE_CONNECTION_LOAD_EXTENSION_METHODDEF) */
731-
/*[clinic end generated code: output=9620be094a4fea95 input=a9049054013a1b77]*/
713+
/*[clinic end generated code: output=c1bf09db3bcd0105 input=a9049054013a1b77]*/

Modules/_sqlite/connection.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -329,20 +329,6 @@ int pysqlite_connection_register_cursor(pysqlite_Connection* connection, PyObjec
329329
}
330330

331331

332-
/*[clinic input]
333-
_sqlite3.Connection.statement_cache as pysqlite_connection_statement_cache
334-
335-
Return the connection statement cache.
336-
[clinic start generated code]*/
337-
338-
static PyObject *
339-
pysqlite_connection_statement_cache_impl(pysqlite_Connection *self)
340-
/*[clinic end generated code: output=a88b63d0c46650ba input=32465d5ec271ca8c]*/
341-
{
342-
return Py_NewRef(self->statement_cache);
343-
}
344-
345-
346332
/*[clinic input]
347333
_sqlite3.Connection.cursor as pysqlite_connection_cursor
348334
@@ -1954,7 +1940,6 @@ static PyMethodDef connection_methods[] = {
19541940
PYSQLITE_CONNECTION_SET_AUTHORIZER_METHODDEF
19551941
PYSQLITE_CONNECTION_SET_PROGRESS_HANDLER_METHODDEF
19561942
PYSQLITE_CONNECTION_SET_TRACE_CALLBACK_METHODDEF
1957-
PYSQLITE_CONNECTION_STATEMENT_CACHE_METHODDEF
19581943
{NULL, NULL}
19591944
};
19601945

0 commit comments

Comments
 (0)