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

  • cache_path (PathOrStr, optional) – Set the path used for caching LO profile data. 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.

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 cache_path: Path | None

Gets/Sets cache 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