Skip to content

[V9.1˖] Configuring a Solr driver

Georges.L edited this page Mar 25, 2022 · 4 revisions

As of Phpfastcache 9.1 a new Solr driver support has been added 🎉

⚠️ Phpfastcache requires Solarium 6.x (or greater) to be installed as a composer dependency for the Solr driver.

The configuration is pretty simple, as always:

/** @var SolrConfig $solrConfig */
$solrConfig = new SolrConfig();
$solrConfig->setCoreName('phpfastcache'); // Optional: Default value
$solrConfig->setPort(8983); // Optional: Default value
$solrConfig->setHost('127.0.0.1'); // Optional: Default value
$solrConfig->setPath('/'); // Optional: Default value
$solrConfig->setScheme('http'); // Optional: Default value



/**
 * Optional:
 *
 * You can change the mapping schema used by Phpfastcache.
 * The keys are the Phpfastcache internal index. All required.
 * The values are the name of your Solr schema.
 */
$solrConfig->setMappingSchema([
    ExtendedCacheItemPoolInterface::DRIVER_KEY_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_KEY_WRAPPER_INDEX . '_s',
    ExtendedCacheItemPoolInterface::DRIVER_DATA_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_DATA_WRAPPER_INDEX . '_s',
    ExtendedCacheItemPoolInterface::DRIVER_EDATE_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_EDATE_WRAPPER_INDEX . '_ss',
    ExtendedCacheItemPoolInterface::DRIVER_MDATE_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_MDATE_WRAPPER_INDEX . '_ss',
    ExtendedCacheItemPoolInterface::DRIVER_CDATE_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_CDATE_WRAPPER_INDEX . '_ss',
    TaggableCacheItemPoolInterface::DRIVER_TAGS_WRAPPER_INDEX => TaggableCacheItemPoolInterface::DRIVER_TAGS_WRAPPER_INDEX . '_ss',
]);

/**
 * Optional:
 *
 * You can change the PSR-14 event dispatcher service used (and required) by solarium, by your own one.
 */
// $solrConfig->setEventDispatcher($yourEventDispatcher);


$cacheInstance = CacheManager::getInstance('Solr', $solrConfig);

However keep in minds that Phpfastcache expects the following fields to be type-configured:

    ExtendedCacheItemPoolInterface::DRIVER_KEY_WRAPPER_INDEX => Expect type "string" field
    ExtendedCacheItemPoolInterface::DRIVER_DATA_WRAPPER_INDEX => Expect type "string" field
    ExtendedCacheItemPoolInterface::DRIVER_EDATE_WRAPPER_INDEX => Expect type "strings" field
    ExtendedCacheItemPoolInterface::DRIVER_MDATE_WRAPPER_INDEX => Expect type "strings" field
    ExtendedCacheItemPoolInterface::DRIVER_CDATE_WRAPPER_INDEX => Expect type "strings" field
    TaggableCacheItemPoolInterface::DRIVER_TAGS_WRAPPER_INDEX => Expect type "strings" field

Please note the difference above between "string" and "strings" (array of strings).

If you found a bug please feel free to open a new issue 😃

Clone this wiki locally