0
$\begingroup$

I'm trying to use cached_property to help store unchanging node and socket references for my addon to access quickly. Still, I noticed that it doesn't actually cache them and may actually do away with the cached_property altogether. The __dict__ results in an empty dictionary even when testing in the Python Console.

Test Code:

import bpy
import time
from functools import cached_property

class MyClasss(bpy.types.PropertyGroup):
    @cached_property
    def test(self):
        time.sleep(2)
        return 3

class ShouldWork:
    def __init__(self):...
    
    @cached_property
    def test(self):
        time.sleep(2)
        return 3

def register():
    bpy.utils.register_class(MyClasss)
    
    bpy.types.Scene.fail = bpy.props.PointerProperty(type=MyClasss)
    bpy.types.Scene.work = ShouldWork()

def unregister():
    del bpy.types.Scene.work
    del bpy.types.Scene.fail
    bpy.utils.unregister_class(MyClasss)
    
if __name__ == "__main__":
    register()

Calling the work one will sleep on the first call and then all calls afterward will return 3 immediately. The fail one always sleeps.

Any help would be excellent! Thanks!

$\endgroup$

0

You must log in to answer this question.

Browse other questions tagged .