The flatsurf.cache Module¶
Adapts sage.misc.cachefunc
for sage-flatsurf.
Some methods on surfaces in sage-flatsurf benefit a lot from caching. However,
we cannot simply put @cached_method
on these surfaces since they are often
defined in a class that is used by both, mutable and immutable surfaces.
Caching for mutable surfaces would be incorrect, or we would have to manually
clear caches upon mutation.
Therefore, we add a decorator @cached_surface_method
that only caches if
the surface is immutable.
EXAMPLES:
sage: from flatsurf import MutableOrientedSimilaritySurface, translation_surfaces
sage: S = MutableOrientedSimilaritySurface.from_surface(translation_surfaces.square_torus())
sage: S.edge_matrix(0, 0) is S.edge_matrix(0, 0)
False
When we call
flatsurf.geometry.surface.MutablePolygonalSurface.set_immutable()
,
caching is enabled for this method:
sage: S.set_immutable()
sage: S.edge_matrix(0, 0) is S.edge_matrix(0, 0)
True
- class flatsurf.cache.CachedSurfaceMethod(f, name, key, do_pickle)[source]¶
Customizes a method in a class so that it conditionally enables caching just like SageMath’s
sage.misc.cachefunc.CachedMethod
does.