HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/cache/__pycache__/__init__.cpython-310.pyc
o

�N�g�.�@sldZddlZddlZddlZddlZddlZddlmZe�	e
�Zdd�ZGdd�d�Z
Gdd	�d	e
�ZdS)
z\
Loader mechanism for caching data, with data expiration, etc.

.. versionadded:: 2016.11.0
�N)�OrderedDictcKs&|�dd�r	t}nt}||fi|��S)z�
    Creates and returns the cache class.
    If memory caching is enabled by opts MemCache class will be instantiated.
    If not Cache class will be returned.
    �memcache_expire_secondsr)�get�MemCache�Cache)�opts�kwargs�cls�r
�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/cache/__init__.py�factorysrc@sleZdZdZddd�Zdd�Zedd��Zdd	d
�Zdd�Z	d
d�Z
dd�Zddd�Zdd�Z
ddd�ZdS)ra�
    Base caching object providing access to the modular cache subsystem.

    Related configuration options:

    :param cache:
        The name of the cache driver to use. This is the name of the python
        module of the `salt.cache` package. Default is `localfs`.

    Terminology:

    Salt cache subsystem is organized as a tree with nodes and leafs like a
    filesystem. Cache consists of banks. Each bank can contain a number of
    keys. Each key can contain a dict or any other object serializable with
    `salt.payload`. I.e. any data object in the cache can be
    addressed by the path to the bank and the key name:
        bank: 'minions/alpha'
        key:  'data'

    Bank names should be formatted in a way that can be used as a
    directory structure. If slashes are included in the name, then they
    refer to a nested structure.

    Key name is a string identifier of a data container (like a file inside a
    directory) which will hold the data.
    NcKsZ||_|dur|�dtjj�|_n||_|�dtjjd�|_d|_	||_
|j|j
d<dS)N�cachedir�cache)rr�saltZsyspathsZ	CACHE_DIRr
ZconfigZDEFAULT_MASTER_OPTS�driver�_modules�_kwargs)�selfrr
rr
r
r�__init__;szCache.__init__cCsFtj�|j�|_|j�d�}||jvr|j||j�|_dSi|_dS)Nz.init_kwargs)r�loaderrrrr�modulesr�r�funr
r
rZ__lazy_initFs


zCache.__lazy_initcCs|jdur	|��|jS�N)r�_Cache__lazy_init)rr
r
rrNs
z
Cache.modulescKs�|�dd�}|�||�}d}|durd}ntt���||kr!d}|�||�}	|	r-|durU|durGg}	|di|��}
|
D]	}|	�||��q<n|di|��}	|�|||	�|	S)aI
        Check cache for the data. If it is there, check to see if it needs to
        be refreshed.

        If the data is not there, or it needs to be refreshed, then call the
        callback function (``fun``) with any given ``**kwargs``.

        In some cases, the callback function returns a list of objects which
        need to be processed by a second function. If that is the case, then
        the second function is passed in as ``loop_fun``. Each item in the
        return list from the first function will be the only argument for the
        second function.
        �expirei�QFNTr
)r�updated�int�time�fetch�append�store)r�bank�keyrZloop_funrZexpire_secondsrZupdate_cache�data�items�itemr
r
rrTs$�zCache.cachecCs(|j�d�}|j||||fi|j��S)a�
        Store data using the specified module

        :param bank:
            The name of the location inside the cache which will hold the key
            and its associated data.

        :param key:
            The name of the key (or file inside a directory) which will hold
            the data. File extensions should not be provided, as they will be
            added by the driver itself.

        :param data:
            The data which will be stored in the cache. This data should be
            in a format which can be serialized by msgpack.

        :raises SaltCacheError:
            Raises an exception if cache driver detected an error accessing data
            in the cache backend (auth, permissions, etc).
        z.store�rrr)rr"r#r$rr
r
rr!zszCache.storecC�&|j�d�}|j|||fi|j��S)a�
        Fetch data using the specified module

        :param bank:
            The name of the location inside the cache which will hold the key
            and its associated data.

        :param key:
            The name of the key (or file inside a directory) which will hold
            the data. File extensions should not be provided, as they will be
            added by the driver itself.

        :return:
            Return a python object fetched from the cache or an empty dict if
            the given path or key not found.

        :raises SaltCacheError:
            Raises an exception if cache driver detected an error accessing data
            in the cache backend (auth, permissions, etc).
        z.fetchr'�rr"r#rr
r
rr��zCache.fetchcCr()a�
        Get the last updated epoch for the specified key

        :param bank:
            The name of the location inside the cache which will hold the key
            and its associated data.

        :param key:
            The name of the key (or file inside a directory) which will hold
            the data. File extensions should not be provided, as they will be
            added by the driver itself.

        :return:
            Return an int epoch time in seconds or None if the object wasn't
            found in cache.

        :raises SaltCacheError:
            Raises an exception if cache driver detected an error accessing data
            in the cache backend (auth, permissions, etc).
        z.updatedr'r)r
r
rr�r*z
Cache.updatedcCs(|j�d�}|j||fd|i|j��S)a�
        Remove the key from the cache bank with all the key content. If no key is specified remove
        the entire bank with all keys and sub-banks inside.

        :param bank:
            The name of the location inside the cache which will hold the key
            and its associated data.

        :param key:
            The name of the key (or file inside a directory) which will hold
            the data. File extensions should not be provided, as they will be
            added by the driver itself.

        :raises SaltCacheError:
            Raises an exception if cache driver detected an error accessing data
            in the cache backend (auth, permissions, etc).
        z.flushr#r'r)r
r
r�flush�szCache.flushcCs$|j�d�}|j||fi|j��S)a
        Lists entries stored in the specified bank.

        :param bank:
            The name of the location inside the cache which will hold the key
            and its associated data.

        :return:
            An iterable object containing all bank entries. Returns an empty
            iterator if the bank doesn't exists.

        :raises SaltCacheError:
            Raises an exception if cache driver detected an error accessing data
            in the cache backend (auth, permissions, etc).
        z.listr')rr"rr
r
r�list�sz
Cache.listcCr()a	
        Checks if the specified bank contains the specified key.

        :param bank:
            The name of the location inside the cache which will hold the key
            and its associated data.

        :param key:
            The name of the key (or file inside a directory) which will hold
            the data. File extensions should not be provided, as they will be
            added by the driver itself.

        :return:
            Returns True if the specified key exists in the given bank and False
            if not.
            If key is None checks for the bank existense.

        :raises SaltCacheError:
            Raises an exception if cache driver detected an error accessing data
            in the cache backend (auth, permissions, etc).
        z	.containsr'r)r
r
r�contains�szCache.containsr)�__name__�
__module__�__qualname__�__doc__rr�propertyrrr!rrr+r,r-r
r
r
rrs


&
rcsjeZdZdZiZ�fdd�Zedd��Zdd�Ze	dd	��Z
�fd
d�Z�fdd
�Zd�fdd�	Z
�ZS)rza
    Short-lived in-memory cache store keeping values on time and/or size (count)
    basis.
    csht�j|fi|��|�dd�|_|�dd�|_|�dd�|_|�dd�|_|jr/d|_d|_d|_	dS)	Nr�
Zmemcache_max_itemsiZmemcache_full_cleanupFZmemcache_debugr)
�superrrr�max�cleanup�debug�call�hit�_storage)rrr��	__class__r
rr
s
zMemCache.__init__cCsJt��}|j��D]}t|���D]\}}|d||kr!||=qq	dS)Nr)rr$�valuesr,r%)r	r�now�storager#r$r
r
rZ	__cleanups��zMemCache.__cleanupcCs,|j�d�}||jvr|j||j�S|jS)Nz.storage_id)rrrrr
r
r�_get_storage_id"s
zMemCache._get_storage_idcCs:|jdur|��}|tjvrt�tj|<tj||_|jSr)r:r@rr$r)rZ
storage_idr
r
rr?)s

zMemCache.storagecs�|jr
|jd7_t��}|j�||fd�}|durM|d|j|krM|jr>|jd7_t�d|j|jt|j�|j�||d<||j||f<|dSt	��
||�}t|j�|jkrt|j
ret�|j�t|j�|jkrt|jjdd�||g|j||f<|S)N�rz(MemCache stats (call/hit/rate): %s/%s/%sF��last)r7r8rr?�poprr9�log�floatr4r�lenr5r6r�_MemCache__cleanup�popitem)rr"r#r>�recordr$r;r
rr2s0�zMemCache.fetchcs||j�||fd�t��|||�t|j�|jkr1|jr"t�|j	�t|j�|jkr1|jj
dd�t��|g|j||f<dS)NFrB)r?rDr4r!rGr5r6rrHrrIr)rr"r#r$r;r
rr!PszMemCache.storeNcsZ|durt|j�D]\}}||kr|j�||f�q	n	|j�||fd�t��||�dSr)�tupler?rDr4r+)rr"r#Zbank_Zkey_r;r
rr+Zs��zMemCache.flushr)r.r/r0r1r$r�classmethodrHr@r2r?rr!r+�
__classcell__r
r
r;rrs
	

r)r1�loggingrZsalt.configrZsalt.loaderZ
salt.syspathsZsalt.utils.odictr�	getLoggerr.rErrrr
r
r
r�<module>s

f