parse cache policy from name

This commit is contained in:
lionsoul2014 2025-12-06 12:23:52 +08:00
parent dde56752af
commit 48dce3545e
2 changed files with 25 additions and 0 deletions

View File

@ -1,6 +1,7 @@
// Copyright 2022 The Ip2Region Authors. All rights reserved. // Copyright 2022 The Ip2Region Authors. All rights reserved.
// Use of this source code is governed by a Apache2.0-style // Use of this source code is governed by a Apache2.0-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package org.lionsoul.ip2region.service; package org.lionsoul.ip2region.service;
import java.io.IOException; import java.io.IOException;
@ -80,4 +81,17 @@ public class Config {
sb.append('}'); sb.append('}');
return sb.toString(); return sb.toString();
} }
public static final int cachePolicyFromName(String name) throws InvalidCachePolicyException {
final String lName = name.toLowerCase();
if (lName.equals("file") || lName.equals("nocache")) {
return NoCache;
} else if (lName.equals("vectorindex") || lName.equals("vindex") || lName.equals("vindexcache")) {
return VIndexCache;
} else if (lName.equals("content") || lName.equals("buffercache")) {
return BufferCache;
} else {
throw new InvalidCachePolicyException("invalid cache policy `" + name + "`");
}
}
} }

View File

@ -0,0 +1,11 @@
// Copyright 2022 The Ip2Region Authors. All rights reserved.
// Use of this source code is governed by a Apache2.0-style
// license that can be found in the LICENSE file.
package org.lionsoul.ip2region.service;
public class InvalidCachePolicyException extends Exception {
public InvalidCachePolicyException(String str) {
super(str);
}
}