是否可以缓存python suds客户端? [英] Is it possible to cache a python suds client?

查看:123
本文介绍了是否可以缓存python suds客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在针对wsdl文件及其对应的50多个xsd文件运行python suds。以下对 Client 的调用大约需要90秒:

 来自肥皂水。客户端导入客户端
url ='http:// localhost:7080 / webservices / WebServiceTestBean?wsdl'
客户端=客户端(url)

运行上面的最后一行后,得到一个 Client 实例。创建该客户端需要很长时间。缓存是否适用于Python对象,还是仅限于诸如字符串和整数之类的基元?



这是我想在代码中执行的操作,语法是错误的,但是它传达了我想要的内容:



<$从suds.client导入p $ p> 客户端


如果'current_client'在缓存中:
client = cache.get('current_client')
else:
url ='http:// localhost:7080 / webservices / WebServiceTestBean?wsdl'
client = Client(url)
cache.put('current_client',client)


解决方案

suds默认情况下每天会缓存WSDL和XSD文件一天,这样,Client对象的每个实例都不需要单独的URL请求。



90秒似乎是很长的时间,这是花在等待wsdl响应上的时间,还是花在解析wsdl上?如果解析需要花费很长时间,则内置缓存不会有太大帮助。



我以前做过类似的事情,但不是单例模式,我只是使用了模块级全局字典。这是没有所有杂音的单例模式。



类似这样的事情:

  from suds.client import客户端

_clients = {}

def get_client(name):
如果名称不在_clients中:
_clients [name] =客户端(url_for_name)
return _clients [name]


I'm currently running python suds against a wsdl file and its corresponding 50+ xsd files. The following call to Client takes about 90 seconds:

from suds.client import Client
url = 'http://localhost:7080/webservices/WebServiceTestBean?wsdl'
client = Client(url)

After I run the last line above, I get a Client instance. Creating that client takes a long time. Does caching work with Python objects or is it restricted to primitives like strings and integers?

Here's what I want to do in code, the syntax is wrong but it's to convey what I want:

from suds.client import Client


if 'current_client' in cache:
    client = cache.get('current_client')
else:
    url = 'http://localhost:7080/webservices/WebServiceTestBean?wsdl'
    client = Client(url)
    cache.put('current_client', client)

解决方案

suds caches WSDL and XSD files for a day by default so that each instantiation of a Client object doesn't require a separate URL request.

90 seconds seems like a really long time, is that time spent waiting on the wsdl response, or is it spent parsing the wsdl? If it's taking that long to parse it, the built-in caching isn't going to help much.

I've done something like this before, but instead of the singleton pattern, I just used a module-level global dictionary. It's the singleton pattern without all the class noise.

Something like this:

from suds.client import Client

_clients = {}

def get_client(name):
    if name not in _clients:
        _clients[name] = Client(url_for_name)
    return _clients[name]

这篇关于是否可以缓存python suds客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆