BaGet icon indicating copy to clipboard operation
BaGet copied to clipboard

Read-through caching isn't working

Open russabyss opened this issue 3 years ago • 13 comments

It seems to be, that read-through caching is not working at all. My BaGet v0.3.0-preview5 is installed over IIS on Windows Server 2012 with netcore hosting bundle.

appsettings.json contains following:

  "Mirror": {
    "Enabled": true,
    // Uncomment this to use the NuGet v2 protocol
    //"Legacy": true,
    "PackageSource": "https://api.nuget.org/v3/index.json"
  }

Everything works fine except read-through caching - I can't install or restore any package if it was not previously pushed to BaGet, neither with nuget.exe nor dotnet CLI, getting error: NU1101.

For example: nuget install EasyCaching.InMemory -Version 1.2.0 -Source http://***-***.***.***/v3/index.json

Returns: Package 'EasyCaching.InMemory 1.2.0' is not found in the following primary source(s): 'http://***-***.***.***/v3/index.json'. Please verify all your online package sources are available (OR) package id, version are specified correctly.

What is expected behavior with read-through caching? As I suppose, if there is no package on local server, it should search forward on nuget.org, and automatically cache package if it was found?

I tried to uncomment "Legacy" line and/or change source to nuget.org/v2 - with no results.

Is there something I misunderstand? Wondering, what I'm doing wrong.

Found this reply from @fourpastmidnight , so it makes me think, that problem is reproducable.

Thanks for any help.

russabyss avatar Apr 21 '21 17:04 russabyss

I am facing the same issue. When I run the Baget from command line using dotnet Baget.dll, when I update a package from Visual studio for example it downloads the package and index it locally. When I add the Baget in IIS then it does not do anything... Also the search is not working in both environments, either running from command or from IIS. When I am trying to search for a package that does not exists locally, e.g. Newtonsoft, it looks like does not search the nuget.org api and does not return any results.

tkardaridis avatar Jul 08 '21 10:07 tkardaridis

Read through caching doesn't work for me, either. Everything else works great. Is there a patch that fixes read through caching?

I'm running the latest version: v0.4.0-preview2. On a Windows server VM with appsettings.json configuration changes (for read-through), from here: https://loic-sharma.github.io/BaGet/configuration/

I've searched through old issues and this problem appears to have been solved, before. Is there additional configuration to make this function?

Thanks!

Lee

LeeWhite187 avatar Dec 14 '21 23:12 LeeWhite187

Weird, I'm not able to reproduce this issue. Could you try increasing the console log level to Debug and sharing any exceptions or errors you see in the logs?

Here's how to update your configs to increase the console log level to Debug:

{
  ...
  "Logging": {
    "IncludeScopes": false,
    "Debug": {
      "LogLevel": {
        "Default": "Warning"
      }
    },
    "Console": {
      "LogLevel": {
        "Microsoft.Hosting.Lifetime": "Information",
-       "Default": "Warning"
+       "Default": "Debug"
      }
    }
  }
}

loic-sharma avatar Dec 15 '21 02:12 loic-sharma

doesn't work for me also Can you explain how it should work? I've added baget address as new nuget source in Visual Studio, when I select nuget.org as a source it can successfully find let's say Nlog package: 2021-12-22_11-43-13

If I select Baget as a source it can't find: 2021-12-22_11-42-27

When I try to install package explicitly as topic starter I get the same error:

nuget install NLog -Version 4.7.1.3 -Source http://my.baget.address:8081/v3/index.json
Feeds used:
  <local package folder>
  http://my.baget.address:8081/v3/index.json



Attempting to gather dependency information for package 'NLog.4.7.1.3' with respect to project '<ProjectPath>', targeting 'Any,Version=v0.0'
Package 'NLog 4.7.1.3' is not found in the following primary source(s): '<local package folder>,http://my.baget.address:8081/v3/index.json'. Please verify all your online package sources are available (OR) package id, version are specified correctly.

There are no errors/exceptions in console logs even if I enable Debug logs.

Ngobo avatar Dec 22 '21 08:12 Ngobo

During remote debugging I found out, that our host server, where BaGet is hosted, has some certificates issues, so all attempts to get list of packages from api.nuget.org fail with corresponding exceptions, because of untrusted cert.

Meanwhile, I couldn't get any logs from BaGet, cause IIS redirects all console output to nullstream.

I'll try to reproduce the problem, when security issues will be resolved, but almost sure, that it'll be ok.

russabyss avatar Dec 22 '21 17:12 russabyss

i have configed the appsetting.json but it's not work

94`6CI)NYOFQ2$VM{3H46YH

youxiaotian avatar Apr 01 '22 09:04 youxiaotian

I turned up logging, but can't locate where the logging target outputs log files. That doesn't seem configurable in this version. Is there more to the setup instruction to choose a specific logging file target path?

LeeWhite187 avatar Apr 01 '22 10:04 LeeWhite187

I turned up logging, but can't locate where the logging target outputs log files. That doesn't seem configurable in this version. Is there more to the setup instruction to choose a specific logging file target path?

hi~ i known how it works 。 actually, it's works。 at first , i think when i search in index page, if local dosen't exit the package, then it will research to the nuget.org api and return for me. but No! it will only search the nuget.org by xxx/search/ be called.

how to call the xxx/search ? open your virtural studio ,and right click your project and left click the 'manager nuget pacages' find the package source and add our private source (if you don't known how to add a package source ,you can google it, so easy)

then , chose the 'all' and install a pacakage ,like 'Newtonsoft.Json' by version 9.0.1 then , chose the 'your private source' which you add just now, then , click the installed tab you can find the 'Newtonsoft.Json' has a new version button , update it then , open the baget adress ,you will find 'Newtonsoft.Json' appeared

all other package can do like this,

i call this action 'give baget a seed, then it will load'

finally , i hope baget will search the mirror__PackageSource address eveytime when i searched. then i can get the pacakage which local not exit more easy.

author do not do this 'merge' (i call this action 'merge' which merge the local result and remote result . lol ),maybe has his own considerations.

hope this advice can help you .

youxiaotian avatar Apr 02 '22 06:04 youxiaotian

Read-though caching is not working for me too

biju-ps avatar Sep 24 '22 10:09 biju-ps

Read-though caching is working for me and it's quite good feature but I must have build the code myself and deploy it this way. The official docker version does not work properly, it fails with strange PostgreSQL error.

This is a working docker-compose.yml with Traefik as proxy and basic authentication

version: '3.3'
services:
  baget-nuget-server:
    build: "./build/"
    networks:
      - traefik
    volumes:
      - ./data:/var/baget
    # ports:
    #   - 8000:80
    env_file:
        - ./.env
    labels:
      - traefik.enable=true
      # Public
      - traefik.http.routers.baget-nuget-server.rule=Host(`nuget.ourserver.com`)
      - traefik.http.services.baget-nuget-server.loadbalancer.server.port=80
      - traefik.http.routers.baget-nuget-server.service=baget-nuget-server
      - traefik.http.routers.baget-nuget-server.tls=true
      - traefik.http.routers.baget-nuget-server.tls.certresolver=le
      - traefik.http.routers.baget-nuget-server.entrypoints=websecure
      - traefik.http.routers.baget-nuget-server.middlewares=baget-nuget-server-auth
      - traefik.http.middlewares.baget-nuget-server-auth.basicauth.headerField=X-WebAuth-User
      - traefik.http.middlewares.baget-nuget-server-auth.basicauth.usersfile=./etc/traefik/userfiles/baget.users
networks:
  traefik:
    external: true

build folder contains whole src folder and Dockerfile

.env file looks like this, with Debug logging and very strange property Storage__Path that I did not find in code but it still works :-)

ApiKey=xxxxxxxxxxxxxxxxx
PackageDeletionBehavior=HardDelete
AllowPackageOverwrites=true
Storage__Type=FileSystem
Storage__Path=/var/baget
Database__Type=PostgreSql
Database__ConnectionString=Server=our-postgresql-server;Port=5432;Database=baget_nuget_server;User Id=baget_nuget_server;Password=Our baget very secure password;
Search__Type=Database
Mirror__Enabled=true
Mirror__PackageSource=https://api.nuget.org/v3/index.json
Logging__Console__LogLevel__Default=Debug

To use it in a Dockerfile of some other project you need to do this https://stackoverflow.com/a/76177774/5556714

Result image

OndrejValenta avatar May 05 '23 00:05 OndrejValenta

Well it works, but in a bit of a different way the most people expect. Nothing is displayed in web ui search, cause search request hits only internal database and is not redirected to PackageSource in appsettings.json.

Principle is the same, so here's explanation for Visual Studio:

  1. make sure nuget.org package source is present and enabled.
  2. enable read-through as described in the docs
  3. In Visual Studio add package source to BaGet server
  4. move BaGet package source above the nuget.org package source

Here's how it looks in NuGet.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="BaGet" value="http://dev-server:5000/v3/index.json" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
  1. In 'NuGet Package Manager' set 'Package source' to 'All'
  2. enter a query in the search box, select a required package and click 'Install' image Only now if the requested package is missing on a BaGet server it will be downloaded from the PackageSource
  3. To verify that the package is present on the BaGet server, select your BaGet source in 'Package source' drop down In 'NuGet Package Manager' or open BaGet web ui. image

Hope this helps.

mii-key avatar Jul 11 '23 10:07 mii-key

does this work also with nuget v2 or just v3? (read through mirror cache), I wasn't able to get results. would be great if also indexing worked... or if baget could just background cache locally and mirror an external source, without having to specify that in nuget.config in the client

jkone27 avatar Jul 31 '23 09:07 jkone27

Hi everyove. Read-through work if you set two settings in Environment(not appsetings.json) Mirror__Enabled=true Mirror__PackageSource=https://api.nuget.org/v3/index.json

FaraSys avatar Jan 22 '24 08:01 FaraSys