Poco::OSP

class CodeCache

File Information

Library: OSP
Package: Util
Header: Poco/OSP/CodeCache.h

Description

CodeCache is a utility class that manages the code cache directory where the shared libraries of resolved bundles are kept.

Under certain circumstances, multiple OSP processes can shared the same code cache directory. This is not recommended, but may be done to optimize a system's resource usage. If the codeCache is shared between multiple processes, all processes must use the same versions of common bundles. In other words, while different processes can run different sets of bundles, all bundles used by multiple processes must be the same, in order to prevent conflicts caused by incompatible shared libraries in the common code cache.

See the CodeCache constructor for enabling support for a shared code cache.

Member Summary

Member Functions: clear, hasLibrary, installLibrary, libraryTimestamp, lock, mutexName, pathFor, uninstallLibrary, unlock

Types Aliases

Lock

using Lock = Poco::ScopedLock < CodeCache >;

Constructors

CodeCache

CodeCache(
    const std::string & path,
    bool isShared = false
);

Creates the CodeCache, using the given path.

If isShared is true, the codeCache is considered shared among multiple processes and a named mutex is used to guard access to it.

If the cache directory does not exist, it is created.

Destructor

~CodeCache

~CodeCache();

Destroys the CodeCache.

Member Functions

clear

void clear();

Clears the cache by removing the entire cache directory.

hasLibrary

bool hasLibrary(
    const std::string & name
);

Returns true if a library with the given name is stored in the code cache.

The name must not contain an filename extension.

installLibrary

void installLibrary(
    const std::string & name,
    std::istream & istr
);

Installs the library with the given name, which must not contain an extension, into the code cache.

libraryTimestamp

Poco::Timestamp libraryTimestamp(
    const std::string & name
);

Returns library last modification timestamp.

The name must not contain an filename extension.

lock

void lock();

For a shared CodeCache, locks the code cache directory.

Does nothing if the codeCache is not shared.

pathFor

std::string pathFor(
    const std::string & name,
    bool appendSuffix = true
);

Returns the full path for the library with the given name. If appendSuffix is true (default), appends the appropriate suffix for debug version and OS dynamic library extension.

uninstallLibrary

void uninstallLibrary(
    const std::string & name
);

Removes the library with the given name from the cache directory.

unlock

void unlock();

For a shared CodeCache, unlocks the code cache directory.

Does nothing if the codeCache is not shared.

mutexName protected static

static std::string mutexName(
    const std::string & path
);

Securely control IoT edge devices from anywhere   Connect a Device