Class ObjectCache


  • public class ObjectCache
    extends Object
    Cache for LinkML objects.

    Several LinkML objects (especially all definitions, e.g. class definitions, slot definitions, etc.) live in a global namespace where they are identified by the value of their identifier slot. This object represents that global namespace.

    • Constructor Detail

      • ObjectCache

        public ObjectCache()
    • Method Detail

      • getObject

        public <T> T getObject​(Class<T> type,
                               String name,
                               boolean create)
                        throws LinkMLRuntimeException
        Looks up for an object with the specified name.
        Type Parameters:
        T - The type of object to return.
        Parameters:
        type - The type of object to return.
        name - The name of the object to return.
        create - If true, the object will be created and added to the cache if it did not already exist.
        Returns:
        The object that was in the cache or have been newly created, or null if (1) the object that was in the cache was not of the expected type, or (2) the object was not in the cache and create is false.
        Throws:
        LinkMLRuntimeException - If the specified type of object is not one that can be cached (because it has no identifier slot), or if the object could not be created as needed.
      • getObject

        public <T> T getObject​(Class<T> type,
                               String name)
                        throws LinkMLRuntimeException
        Looks up for an object with the specified name.
        Type Parameters:
        T - The type of object to return.
        Parameters:
        type - The type of object to return.
        name - The name of the object to return.
        Returns:
        The requested object, or null if the object was not in the cache or was not of the expected type.
        Throws:
        LinkMLRuntimeException - If the specified type of object is not one that can be cached, because it has no identifier slot.
      • getSize

        public int getSize()
        Gets the number of objects in the cache.