clear_cache: number or blocks to keep

This commit is contained in:
Alexander 2017-09-23 04:20:53 +03:00
parent 6a435793d8
commit 4b85230726
2 changed files with 8 additions and 5 deletions

View File

@ -129,14 +129,15 @@ class TestCoreMemory(PillowTestCase):
Image.core.set_block_size(4096)
Image.new('RGB', (256, 256))
Image.new('RGB', (256, 256))
Image.core.clear_cache()
# Keep 16 blocks in cache
Image.core.clear_cache(16)
stats = Image.core.get_stats()
self.assertGreaterEqual(stats['new_count'], 2)
self.assertGreaterEqual(stats['allocated_blocks'], 64)
self.assertGreaterEqual(stats['reused_blocks'], 64)
self.assertGreaterEqual(stats['freed_blocks'], 64)
self.assertEqual(stats['blocks_cached'], 0)
self.assertGreaterEqual(stats['freed_blocks'], 48)
self.assertEqual(stats['blocks_cached'], 16)
def test_large_images(self):
Image.core.reset_stats()

View File

@ -3466,10 +3466,12 @@ _set_blocks_max(PyObject* self, PyObject* args)
static PyObject*
_clear_cache(PyObject* self, PyObject* args)
{
if (!PyArg_ParseTuple(args, ":clear_cache"))
int i = 0;
if (!PyArg_ParseTuple(args, "|i:clear_cache", &i))
return NULL;
ImagingMemoryClearCache(&ImagingDefaultArena, 0);
ImagingMemoryClearCache(&ImagingDefaultArena, i);
Py_INCREF(Py_None);
return Py_None;