# PFront results gazillion amount of cache file, how to avoid it?

**URL:** <https://discourse.processing.org/t/pfront-results-gazillion-amount-of-cache-file-how-to-avoid-it/36737>\
**Category:** Coding Questions\
**Created:** [May 5, 2022, 3:57pm UTC](https://discourse.processing.org/t/pfront-results-gazillion-amount-of-cache-file-how-to-avoid-it/36737 "2022-05-05T15:57:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![psamead](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@psamead](https://discourse.processing.org/u/psamead)\
**Post date:** [May 5, 2022, 3:57pm UTC](https://discourse.processing.org/t/pfront-results-gazillion-amount-of-cache-file-how-to-avoid-it/36737/1 "2022-05-05T15:57:08Z")

</div>

Hi my friends,  
I am trying to convert the [guest tutorial](https://www.youtube.com/watch?v=S1TQCi9axzg&t=1s) [matrix rain](https://github.com/emilyxxie/green_rain/blob/master/sketch.js) from coding train to processing version. But I found that the code will result gazillion amount of cache file to my disk, maybe because I am using PFont. Each steam of characters will take as cache file. I wonder if there is way to avoid to build such amount of cache by changing the code or cleaning up the caches when the code running.  
here is my code:

```auto
float symbolSize;
Stream[] streams;
int streamSize;

void setup()
{
  size(800, 400);
  background(0, 100);
  symbolSize = 15;
  streamSize = (int)(width/symbolSize);
  
  streams = new Stream[streamSize]; 
  
  int x = 0;
  int y = int(random(-1000, 0));
  for(int i = 0; i <= streamSize-1; i++)
  {
    Stream stream = new Stream(x, y, symbolSize);
    streams[i] = stream;
    x += symbolSize;
  }
}

void draw()
{
  background(0, 100);
  for(Stream s: streams)
  {
    s.render();  
  }
  
}

class Stream
{
  Symbol[] symbols;
  Symbol symbol;
  int totalSymbols;
  float symbolSize;
  float rainSpeed;
  int x, y;
  float fateInterval;
  
  Stream(int x, int y, float symbolSize)
  {
    this.x = x;
    this.y = y;
    this.symbolSize = symbolSize;
    rainSpeed = random(1, 10);
    fateInterval = 1.6;
    totalSymbols = floor(random(5, height/symbolSize-1));
    

    symbols = new Symbol[totalSymbols];
    
    generateSymbols();
    println(totalSymbols);
  }

  void generateSymbols()
  { 
    //boolean first = round(random(0, 4))==1? true:false;
    boolean first = round(random(0, 4))==1;
    float opacity = 255;
    for(int i = 0; i <= totalSymbols-1; i++)
    {
      symbol = new Symbol(x, y, symbolSize, rainSpeed, first, opacity);
      symbol.setToRandomSymbol();
      symbols[i] = symbol;
      y -= symbolSize;
      opacity -= (255/totalSymbols)/fateInterval;
      first = false;
    }
  }

  void render()
  {
    for(Symbol s: symbols)
    {
      if(s.first)
      {
        fill(200, 250, 230, s.opacity);
      }
      else
      {
        fill(10, 250, 110, s.opacity);
      }
      textFont(s.font);
      s.setToRandomSymbol();
      text(s.word, s.x, s.y);
      s.rain();
    }
  }

}

class Symbol
{
  PFont font;
  int x, y;
  char word;
  float size;
  float speed;
  int switchInterval ;
  boolean first;
  float opacity;
  
  Symbol(int _x, int _y, float _size, float _speed, boolean _first, float _opacity)
  {
    x = _x;
    y = _y; 
    size = _size;
    speed = _speed;
    first = _first;
    opacity = _opacity;
    //font = createFont("SawarabiMincho-Regular.ttf", size);
    font = createFont("Yomogi-Regular.ttf", size);
    switchInterval = round(random(2, 25));
  }

  void setToRandomSymbol()
  {
    //float charType = round(random(0, 5));
    if(frameCount%switchInterval == 0)
    {
      //if(charType > 1)
      //{
        // set it to Katakana
        word = char(0x30A0 + floor(random(0, 97)));
      //}
      //else
      //{
      // // set it to numeric 
      // word = char(floor(random(0, 10)));
      //}
    }
  }
  
  void rain()
  {
   
    y = (y >= height)? 0: y+(int)speed;
    println(speed);
  }

}

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 5, 2022, 4:03pm UTC](https://discourse.processing.org/t/pfront-results-gazillion-amount-of-cache-file-how-to-avoid-it/36737/2 "2022-05-05T16:03:52Z")

</div>

> [@psamead](#):
>
> `font = createFont("Yomogi-Regular.ttf", size);`

The statement above is an asset resource loading operation.  
Best place to load assets is inside **setup()**.

---

<div class="post-metadata">

**Author:** ![psamead](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@psamead](https://discourse.processing.org/u/psamead)\
**Post date:** [May 5, 2022, 4:27pm UTC](https://discourse.processing.org/t/pfront-results-gazillion-amount-of-cache-file-how-to-avoid-it/36737/3 "2022-05-05T16:27:56Z")

</div>

Thanks GoToLoop. I figure out it if the statement put in the setup() , It only load the resource once and result one cache file. But if it was in the object, it will load and write the cache file as many as the object occurring.
