Skip to content

Commit

Permalink
Merge pull request #1766 from girder/clear-cache
Browse files Browse the repository at this point in the history
When clearing all caches, better clear vips and gdal caches
  • Loading branch information
manthey authored Jan 9, 2025
2 parents 2e0f0b4 + de8b8cb commit b819db4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Read jp2k compressed associated images in tiff files ([#1754](../../pull/1754))
- Improve writing to zarr sinks from multiple processes ([#1713](../../pull/1713))
- Slightly faster GDAL validateCOG ([#1761](../../pull/1761))
- Improve clearing caches ([#1765](../../pull/1765))

### Changes

Expand Down
11 changes: 10 additions & 1 deletion sources/gdal/large_image_source_gdal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import numpy as np
import PIL.Image

from large_image.cache_util import LruCacheMetaclass, methodcache
from large_image.cache_util import LruCacheMetaclass, _cacheClearFuncs, methodcache
from large_image.constants import (TILE_FORMAT_IMAGE, TILE_FORMAT_NUMPY,
TILE_FORMAT_PIL, SourcePriority,
TileOutputMimeTypes)
Expand Down Expand Up @@ -77,6 +77,15 @@ def _lazyImport():
import pyproj

# isort: on

def _clearGDALCache():
old = gdal.GetCacheMax()
# print('Clearing GDAL cache: size %r, max %r' % (
# gdal.GetCacheUsed(), old))
gdal.SetCacheMax(0)
gdal.SetCacheMax(old)

_cacheClearFuncs.append(_clearGDALCache)
except ImportError:
msg = 'gdal module not found.'
raise TileSourceError(msg)
Expand Down
18 changes: 12 additions & 6 deletions sources/vips/large_image_source_vips/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@


def _clearVipsCache():
old = pyvips.voperation.cache_get_max_files()
pyvips.voperation.cache_set_max_files(0)
pyvips.voperation.cache_set_max_files(old)
old = pyvips.voperation.cache_get_max()
pyvips.voperation.cache_set_max(0)
pyvips.voperation.cache_set_max(old)
oldfiles = pyvips.cache_get_max_files()
oldmax = pyvips.cache_get_max()
oldmem = pyvips.cache_get_max_mem()
# print('Clearing vips cache: size %r, max files %r, max %r, mem %r' % (
# pyvips.cache_get_size(), oldfiles, oldmax, oldmem))
pyvips.cache_set_max_files(0)
# This shouldn't ever go to zero
pyvips.cache_set_max(1)
pyvips.cache_set_max_mem(0)
pyvips.cache_set_max_files(oldfiles)
pyvips.cache_set_max(oldmax)
pyvips.cache_set_max_mem(oldmem)


_cacheClearFuncs.append(_clearVipsCache)
Expand Down

0 comments on commit b819db4

Please sign in to comment.