Skip to content

Commit

Permalink
Merge pull request #418 from mrgnlabs/j/cache-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jkbpvsc authored Dec 10, 2023
2 parents 30fe7e1 + 89cedf8 commit 3021af5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions apps/marginfi-v2-ui/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export function middleware(req: NextRequest) {
const basicAuth = req.headers.get("authorization");
const url = req.nextUrl;
const response = NextResponse.next();
// response.headers.set('Vercel-CDN-Cache-Control', 'private, max-age=10');
// response.headers.set('CDN-Cache-Control', 'private, max-age=10');
// response.headers.set('Cache-Control', 'private, max-age=10');

if (process.env.AUTHENTICATION_DISABLED === "true") {
return response;
Expand Down
5 changes: 4 additions & 1 deletion apps/marginfi-v2-ui/src/utils/mrgnActions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MarginfiAccountWrapper, MarginfiClient, ProcessTransactionError } from "@mrgnlabs/marginfi-client-v2";
import { ExtendedBankInfo, FEE_MARGIN, ActionType } from "@mrgnlabs/marginfi-v2-ui-state";
import { ExtendedBankInfo, FEE_MARGIN, ActionType, clearAccountCache } from "@mrgnlabs/marginfi-v2-ui-state";
import { isWholePosition } from "./mrgnUtils";
import { Connection, PublicKey, Transaction } from "@solana/web3.js";
import { Wallet, processTransaction } from "@mrgnlabs/mrgn-common";
Expand Down Expand Up @@ -89,6 +89,9 @@ async function createAccountAndDeposit({
try {
const squadsOptions = await getMaybeSquadsOptions(walletContextState);
marginfiAccount = await mfiClient.createMarginfiAccount(undefined, squadsOptions);

clearAccountCache(mfiClient.provider.publicKey);

multiStepToast.setSuccessAndNext();
} catch (error: any) {
const msg = extractErrorString(error);
Expand Down
11 changes: 10 additions & 1 deletion packages/marginfi-v2-ui-state/src/store/mrgnlendStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ function createPersistentMrgnlendStore() {
);
}

function createLocalStorageKey(authority: PublicKey): string {
return `marginfi_accounts-${authority.toString()}`;
}

async function getCachedMarginfiAccountsForAuthority(
authority: PublicKey,
client: MarginfiClient
Expand All @@ -87,7 +91,7 @@ async function getCachedMarginfiAccountsForAuthority(
return client.getMarginfiAccountsForAuthority(authority);
}

const cacheKey = `marginfiAccounts-${authority.toString()}`;
const cacheKey = createLocalStorageKey(authority);
const cachedAccounts = window.localStorage.getItem(cacheKey);
debug("cachedAccounts", cachedAccounts);
if (cachedAccounts) {
Expand All @@ -102,6 +106,11 @@ async function getCachedMarginfiAccountsForAuthority(
}
}

export function clearAccountCache(authority: PublicKey) {
const cacheKey = createLocalStorageKey(authority);
window.localStorage.removeItem(cacheKey);
}

const stateCreator: StateCreator<MrgnlendState, [], []> = (set, get) => ({
// State
initialized: false,
Expand Down

2 comments on commit 3021af5

@vercel
Copy link

@vercel vercel bot commented on 3021af5 Dec 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

omni – ./apps/omni

omni-mrgn.vercel.app
omni-one.vercel.app
omni-git-production-mrgn.vercel.app
omni.marginfi.com

@vercel
Copy link

@vercel vercel bot commented on 3021af5 Dec 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.