<commit_before>const ArrayAdapter = Jymfony.Component.Cache.Adapter.ArrayAdapter;
const FilesystemAdapter = Jymfony.Component.Cache.Adapter.FilesystemAdapter;
const CacheItem = Jymfony.Component.Cache.CacheItem;
const CacheItemPoolInterface = Jymfony.Component.Cache.CacheItemPoolInterface;
const InvalidArgumentException = Jymfony.Component.Cache.Exception.InvalidArgumentException;
const AbstractTrait = Jymfony.Component.Cache.Traits.AbstractTrait;
const DateTime = Jymfony.Component.DateTime.DateTime;
const LoggerAwareInterface = Jymfony.Component.Logger.LoggerAwareInterface;
const NullLogger = Jymfony.Component.Logger.NullLogger;

const fs = require('fs');

/**
 * @memberOf Jymfony.Component.Cache.Adapter
 * @abstract
 */
class AbstractAdapter extends implementationOf(CacheItemPoolInterface, LoggerAwareInterface, AbstractTrait) {
    /**
     * Constructor.
     *
     * @param {string} [namespace = '']
     * @param {int} [defaultLifetime = 0]
     */
    __construct(namespace = '', defaultLifetime = 0) {
        /**
         * @type {string}
         *
         * @private
         */
        this._namespace = '' === namespace ? '' : (CacheItem.validateKey(namespace) + ':');
        if (undefined !== this.constructor.MAX_ID_LENGTH && namespace.length > this.constructor.MAX_ID_LENGTH - 24) {
            throw new InvalidArgumentException(__jymfony.sprintf('Namespace must be %d chars max, %d given ("%s")', this.constructor.MAX_ID_LENGTH - 24, namespace.length, namespace));
        }

        /**
         * Create a cache item for the current adapter.
         *
         * @param {string} key
         * @param {*} value
         * @param {boolean} isHit
         *
         * @returns {Jymfony.Component.Cache.CacheItem}
         *
         * @private
         */
        this._createCacheItem = (key, value, isHit) => {
            const item = new CacheItem();
            item._key = key;
            item._value = value;
            item._isHit = isHit;
            item._defaultLifetime = defaultLifetime;

            return item;
        };

        /**
         * @type {Jymfony.Component.Logger.LoggerInterface}
         *
         * @private
         */
        this._logger = new NullLogger();
    }

    /**
     * Creates a system cache pool.
     *
     * @param {string} namespace
     * @param {int} defaultLifetime
     * @param {string} directory
     * @param {Jymfony.Component.Logger.LoggerInterface} [logger]
     */
    static createSystemCache(namespace, defaultLifetime, directory, logger = undefined) {
        const cache = (() => {
            const fsAdapter = new FilesystemAdapter(namespace, defaultLifetime, directory);
            if (fs.accessSync(directory, fs.constants.W_OK)) {
                return fsAdapter;
            }

            return new ArrayAdapter(defaultLifetime);
        })();

        cache.setLogger(logger || new NullLogger());

        return cache;
    }

    /**
     * @inheritdoc
     */
    async getItem(key) {
        const id = await this._getId(key);

        let isHit = false;
        let value = undefined;

        try {
            for (const val of Object.values(await this._doFetch([ id ]))) {
                value = val;
                isHit = true;
            }<commit_msg>[Cache] handle read-only filesystem error when initializing system cache<commit_after>const ArrayAdapter = Jymfony.Component.Cache.Adapter.ArrayAdapter;
const FilesystemAdapter = Jymfony.Component.Cache.Adapter.FilesystemAdapter;
const CacheItem = Jymfony.Component.Cache.CacheItem;
const CacheItemPoolInterface = Jymfony.Component.Cache.CacheItemPoolInterface;
const InvalidArgumentException = Jymfony.Component.Cache.Exception.InvalidArgumentException;
const AbstractTrait = Jymfony.Component.Cache.Traits.AbstractTrait;
const DateTime = Jymfony.Component.DateTime.DateTime;
const LoggerAwareInterface = Jymfony.Component.Logger.LoggerAwareInterface;
const NullLogger = Jymfony.Component.Logger.NullLogger;

const fs = require('fs');

/**
 * @memberOf Jymfony.Component.Cache.Adapter
 * @abstract
 */
class AbstractAdapter extends implementationOf(CacheItemPoolInterface, LoggerAwareInterface, AbstractTrait) {
    /**
     * Constructor.
     *
     * @param {string} [namespace = '']
     * @param {int} [defaultLifetime = 0]
     */
    __construct(namespace = '', defaultLifetime = 0) {
        /**
         * @type {string}
         *
         * @private
         */
        this._namespace = '' === namespace ? '' : (CacheItem.validateKey(namespace) + ':');
        if (undefined !== this.constructor.MAX_ID_LENGTH && namespace.length > this.constructor.MAX_ID_LENGTH - 24) {
            throw new InvalidArgumentException(__jymfony.sprintf('Namespace must be %d chars max, %d given ("%s")', this.constructor.MAX_ID_LENGTH - 24, namespace.length, namespace));
        }

        /**
         * Create a cache item for the current adapter.
         *
         * @param {string} key
         * @param {*} value
         * @param {boolean} isHit
         *
         * @returns {Jymfony.Component.Cache.CacheItem}
         *
         * @private
         */
        this._createCacheItem = (key, value, isHit) => {
            const item = new CacheItem();
            item._key = key;
            item._value = value;
            item._isHit = isHit;
            item._defaultLifetime = defaultLifetime;

            return item;
        };

        /**
         * @type {Jymfony.Component.Logger.LoggerInterface}
         *
         * @private
         */
        this._logger = new NullLogger();
    }

    /**
     * Creates a system cache pool.
     *
     * @param {string} namespace
     * @param {int} defaultLifetime
     * @param {string} directory
     * @param {Jymfony.Component.Logger.LoggerInterface} [logger]
     */
    static createSystemCache(namespace, defaultLifetime, directory, logger = undefined) {
        const cache = (() => {
            try {
                const fsAdapter = new FilesystemAdapter(namespace, defaultLifetime, directory);
                if (fs.accessSync(directory, fs.constants.W_OK)) {
                    return fsAdapter;
                }
            } catch (e) {
                if ('EROFS' !== e.code) {
                    throw e;
                }
            }

            return new ArrayAdapter(defaultLifetime);
        })();

        cache.setLogger(logger || new NullLogger());

        return cache;
    }

    /**
     * @inheritdoc
     */
    async getItem(key) {
        const id = await this._getId(key);

        let isHit = false;
        let value = undefined;

        try {
            for (const val of Object.values(await this._doFetch([ id ]))) {
                value = val;
                isHit = true;
            }
{'fraction_non_alphanumeric': 0.11327433628318584, 'fraction_numerical': 0.0017699115044247787, 'mean_word_length': 2.1776007497656984, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7385566', 'n_tokens_mistral': 1853, 'n_tokens_neox': 1803, 'n_words': 394}