parse cache policy from name
This commit is contained in:
parent
dde56752af
commit
48dce3545e
|
|
@ -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 + "`");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue