Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Set global Firebase app for cache
Browse files Browse the repository at this point in the history
  • Loading branch information
christippett committed Jun 22, 2019
1 parent 55f0db7 commit aa0d6ab
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/django_firebase_cache/realtime_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
from firebase_admin.db import Reference


APP_NAME = "DJANGO_CACHE"
APP_INITIALIZED = False
FIREBASE_APP = None


class RealtimeDatabaseCache(BaseCache):
Expand All @@ -28,9 +27,12 @@ def __init__(self, cache_key, params):
@property
def db(self) -> Reference:
if getattr(self, "_db", None) is None:
if not APP_INITIALIZED:
firebase_admin.initialize_app(options=self._options, name=APP_NAME)
ref = db.reference(self.db_key, app=APP_NAME)
global FIREBASE_APP
if FIREBASE_APP is None:
FIREBASE_APP = firebase_admin.initialize_app(
options=self._options, name="DJANGO_CACHE"
)
ref = db.reference(self.db_key, app=FIREBASE_APP)
if self.key_prefix:
ref = ref.child(self.key_prefix)
self._db: Reference = ref
Expand Down

0 comments on commit aa0d6ab

Please sign in to comment.