Class Cache

Cache is often used in conjunction with ConnectPipe or ConnectSocket

Cache provides caching option for profiles when connecting to LibreOffice(not used in macros). In some cases it is beneficial (such as when testing and debugging) to copy as profile that will be used for a single LibreOffice session.

Cache provides a way to supply a preexisting profile and copy that profile into a temp working directory. When cache is used any changes made in LibreOffice will only last for the session. Once the session is terminated the working dir is invalidated.

Subsequent sessions will get a fresh profile copied from cache.

Cache default settings searches in know locations for current users profile and creates, copies the profile into a temp dir, then sets the temp dir as working dir.

Example connecting using Cache:

from ooodev.loader.lo import Lo
from ooodev.conn.cache import Cache
from ooodev.office.calc import Calc

loader = Lo.load_office(connector=Lo.ConnectSocket(), cache_obj=Cache())
doc = Calc.create_doc(loader)
# do work ...
Lo.close_doc(doc=doc)
Lo.close_office()
class ooodev.conn.cache.Cache(**kwargs)[source]

Office Profile Cache Manager

__init__(**kwargs)[source]

Cache Constructor

Keyword Arguments:
  • use_cache (bool, optional) – Determines if caching is used. Default is True

  • profile_path (PathOrStr, optional) – Set the path used for getting LO profile data. If not set then an attempt is made to copy the user profiler. If set to empty string then no profile will be copied and a new profile will be created. If set to a path then that path will be used. Default is searched for in known locations.

  • working_dir (PathOrStr, optional) – sets the working dir to use. This is the dir that LO profile will be copied to. Defaults to a newly generated temp dir.

  • no_shared_ext (bool, optional) – Determines if shared extensions are used. If set to True then no shared extensions are disabled for the session. Default is False.

Return type:

None

cache_profile()[source]

Copies user profile into cache path if it has not already been cached.

Ignored if use_cache is False

Return type:

None

copy_cache_to_profile()[source]

Copies cached profile to profile dir set in user_profile

Ignored if use_cache is False

Return type:

None

del_working_dir()[source]

Deletes the current working directory of instance.

Ignored if use_cache is False

property no_share_path: Path | None

Gets user No shared extension path

Return type:

Path | None

property profile_path: Path | None

Gets/Sets profile path

The when possible default is obtained by searching in know locations, depending on OS. For instance on Linux will search in ~/.config/libreoffice/4

Return type:

Path | None

property use_cache: bool

Gets/Sets if cache is used. Default is True

Return type:

bool

property user_profile: Path

Gets user profile path

Return type:

Path

property working_dir: Path

Gets/Sets working dir

This property determines the dir LO uses to obtain its profile data. Default to an auto generated tmp dir.

Return type:

Path