문제

SQLALCHEMY는 어떤 종류의 캐싱을 지원하므로 동일한 쿼리를 반복적으로 실행하면 데이터베이스를 쿼리하는 대신 캐시에서 응답을 반환합니까? DB가 업데이트 될 때이 캐시가 자동으로 지워 집니까?

아니면 Cherrypy + Sqlalchemy 설정에서 이것을 구현하는 가장 좋은 방법은 무엇입니까?

도움이 되었습니까?

해결책

우리는 0.6의 임베디드 후크와 함께 예를 들어 매우 포괄적 인 캐싱 솔루션을 가지고 있습니다. 쿼리 서브 클래스 쿼리의 레시피입니다. 비이커를 인식하고 쿼리 옵션을 통해 게으른 로더뿐만 아니라 명시 적 쿼리를위한 쿼리 캐싱을 제어 할 수 있습니다.

나는 지금 그것을 생산 중입니다. 예제 자체는 Dist에 있으며 소개 문서는 다음과 같습니다. http://www.sqlalchemy.org/docs/orm/examples.html#beaker-caching .

업데이트 : Beaker가 이제 교체되었습니다 dogpile 캐싱 : http://docs.sqlalchemy.org/en/latest/orm/examples.html#module-examples.dogpile_caching

다른 팁

두 번째 질문에 대한 답은 아니지만이 링크의 의견에서 SQLALCHEMY가 캐시링을 지원하지 않음을 나타냅니다. http://spyced.blogspot.com/2007/01/why-sqlalchemy-impresses-me.html

까마귀가 말했다 ...

Does SQLAlchemy do any kind of internal caching?

For example, if you ask for the same data twice (or an obvious subset
of the initially requested data) will the database be hit once or twice?

I recently wrote a caching database abstraction layer for an
application and (while fun) it was a fair bit of work to get it to a
minimally functional state. If SQLAlchemy did that I would seriously
consider jumping on the bandwagon.

I've found things in the docs that imply something like this might be
going on, but nothing explicit.
4:36 PM

조나단 엘리스가 말했다 ...

No; the author of SA [rightly, IMO] considers caching a separate concern.

What you saw in the docs is probably the SA identity map, which makes it so 
if you load an instance in  two different places, they will refer
to the same object. But the database will still be queried twice, so it is
not a cache in the sense you mean.

Sqlalchemy는 두 가지 유형의 캐시를 지원합니다.

  1. 동일한 쿼리를 반복적으로 실행하도록 결과 세트를 캐싱하면 데이터베이스 대신 캐시가 발생합니다. 사용합니다 dogpile 이를 포함한 다양한 백엔드를 지원합니다 memcached, redis, 및 기본 플랫 파일.

    문서는 여기에 있습니다. http://docs.sqlalchemy.org/en/latest/orm/examples.html#module-examples.dogpile_caching

  2. 캐싱 query Python 통역사가 매번 쿼리 문자열을 수동으로 다시 조정할 필요가 없도록 객체. 이 쿼리가 호출됩니다 baked queries 그리고 캐시가 호출됩니다 baked. 기본적으로 모든 동작을 캐시합니다 sqlalchemy 데이터베이스를 치기 전에 가져 가십시오. 데이터베이스 호출을 줄이지 않습니다. 초기 벤치 마크는 최대 40%의 속도를 보여줍니다. query 코드 진동성이 약간 증가한 트레이드 오프에서 생성 시간.

    문서는 여기에 있습니다. http://docs.sqlalchemy.org/en/latest/orm/extensions/baked.html

또는 약한 참조 dicts (weachref.weakValuedictionary)를 통해 응용 프로그램 수준 캐시를 사용하십시오. 예를 참조하십시오. http://www.sqlalchemy.org/trac/wiki/usagerecipes/uniqueobject

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top