minipack icon indicating copy to clipboard operation
minipack copied to clipboard

Caching does not work as expected

Open heyimalex opened this issue 2 years ago • 0 comments

From the configuration file:

By default c.cache is set to false, which means an application always parses a manifest.json. In development, you should set cache false usually. Instead, setting it true which caches the manifest in memory is recommended basically.

However, all of the helpers call get_manifest_by_key which calls Minipack.configuration.manifests. Looking at the source for manifests:

      def manifests
        raise Error, 'Calling #manifests is only allowed from a root' unless root?

        repo = ManifestRepository.new
        #  Determine if a single manifest mode or multiple manifests(multiple site) mode
        targets =  @children.empty? ? [self] : @children.values
        targets.each do |config|
          # Skip sites that a manifest file is not configured
          next if config.manifest.nil?

          repo.add(config.id, config.manifest, cache: config.cache)
        end
        repo
      end

A new repo is created on every call, which means that new manifest is created on every call, which means that we re-read and parse the manifest file on every call. You can verify this in an irb window. Notice that cache is true but the addresses of the returned manifests are different.

> Minipack.configuration.manifests.default
=> #<Minipack::Manifest:0x00007faea98fc1e0 @path="/opt/platform/manifest.json", @cache=true>
> Minipack.configuration.manifests.default
=> #<Minipack::Manifest:0x00007faea0375fb8 @path="/opt/platform/manifest.json", @cache=true>

heyimalex avatar Nov 29 '23 18:11 heyimalex