PHPackages                             manta\_ray\_media/random\_hero\_bg - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. manta\_ray\_media/random\_hero\_bg

ActiveDrupal-module[Utility &amp; Helpers](/categories/utility)

manta\_ray\_media/random\_hero\_bg
==================================

Pass array of strings and get back single string with cleared cache

1.0.2(5y ago)0490MITPHPPHP &gt;=7.2

Since Aug 10Pushed 5y ago1 watchersCompare

[ Source](https://github.com/MantaRayMedia/random_hero_bg)[ Packagist](https://packagist.org/packages/manta_ray_media/random_hero_bg)[ Docs](https://github.com/MantaRayMedia/random_hero_bg)[ RSS](/packages/manta-ray-media-random-hero-bg/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

Caching for anonymous users
---------------------------

[](#caching-for-anonymous-users)

To solve the problem with the caching for anonymous users, we have been working on 3 different files

```
pubmlst/web/themes/custom/pubmlst/pubmlst.theme
pubmlst/web/modules/custom/random_hero_bg/
```

### node--front.html.twig

[](#node--fronthtmltwig)

We have different random background colours to apply on the hero section, to randomise the colours without cache the results all the time, we used a module with the randomise the colours

```
{% set hero_rand_bg = ['bg-blue','bg-purple','bg-teal','bg-navy'] | randomBackground(hero_rand_test) %}

```

### random\_hero\_bg custom module

[](#random_hero_bg-custom-module)

On RandomHeroBG.php we have two functions, one function to clear first the cache for Anonymous users

```
{
  \Drupal::service('page_cache_kill_switch')->trigger();
  \Drupal::service('cache.render')->invalidateAll();

  // clear caches for anonymous
  Cache::invalidateTags(['HIT']);
}

```

And then another function to delete the random background colour before randomise again the values.

```
public function randomBackground(array $input, $number)
{
  $this->clearCache();
  $key = array_rand($input);
  return $input[$key];
}

```

To double check if it is working, check if the number is changing with this code inside the randomBackground Functions

```
var_dump($number, $key);

```

Check this link for more information about [cache-tags](https://www.drupal.org/docs/drupal-apis/cache-api/cache-tags)

### pubmlst.theme

[](#pubmlsttheme)

Add a preprocess function to clear caches for this specific node type, cleaning the session cache and the variables used on the random

```
function pubmlst_preprocess_node__front(&$variables){
  $variables['#cache'] = [
    'max-age' => 0,
    'contexts' => ['session']
  ];
  $variables['hero_rand_bg']['#cache']['max-age'] = 0;
  $variables['hero_rand_test']['#cache']['max-age'] = 0;
}

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

2108d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d7a79b89bce941cd71c96c6598dbc714c91db5d0be604afe4c33f1487bbc73df?d=identicon)[slejnej](/maintainers/slejnej)

---

Top Contributors

[![slejnej](https://avatars.githubusercontent.com/u/7508599?v=4)](https://github.com/slejnej "slejnej (5 commits)")

---

Tags

drupal

### Embed Badge

![Health badge](/badges/manta-ray-media-random-hero-bg/health.svg)

```
[![Health](https://phpackages.com/badges/manta-ray-media-random-hero-bg/health.svg)](https://phpackages.com/packages/manta-ray-media-random-hero-bg)
```

###  Alternatives

[tripal/tripal

Tripal is a toolkit to facilitate construction of online genomic, genetic (and other biological) websites.

709.9k9](/packages/tripal-tripal)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
