Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caching does not work at all in 3.22, but works just fine in 3.21 #2935

Closed
tandrasi opened this issue Feb 19, 2024 · 2 comments
Closed

Caching does not work at all in 3.22, but works just fine in 3.21 #2935

tandrasi opened this issue Feb 19, 2024 · 2 comments

Comments

@tandrasi
Copy link

Major Version

3.x

Minor Version Number

3.22

Target environment

SharePoint Framework

Additional environment details

  • Node v18.18.0
  • SPFx 1.18.2
  • SharePoint Online

Expected or Desired Behavior

I'm trying to retrieve list items and choice column values from a list. I expect that when I have caching enabled .using(Caching(...)) that it stores cached data in my local storage (now that I type this, I haven't tested changing it to session storage) and reads it on subsequent calls.

Observed Behavior

What I see is:

3.21
Works as expected with all caching and even paged results. Thanks to the following bug report, I see paging was fixed as of 3.21 #2836 and it works great! All other paging works as expected. I can see the cached data written to local storage and it is read correctly. Paged results even retrieve their "getNext()" results correctly (thanks again for that fix in 3.21!).

3.22

  • This version doesn't cache at all unless the request has paging. If my item retrieval request has paging, it will store data to the cache. If not paging, nothing is stored regardless request type.
  • If trying to load a paged cache request, an infinite loop with getNext() will occur as it feels like it never fetches the next bit in the cache and therefore never changes its "hasNext" property to false.
  • This version is completely broken with caching.

Steps to Reproduce

We are using a huge shared library in house. There are many things that are spread between multiple files and classes. So I'll just copy the imports here and then just copy/paste the main functions.

Please see "Observed Behavior" above as that outlines what I'm experiencing. Basically using the same code with 3.21 works yet it completely fails with 3.22 (regarding caching).

import "@pnp/sp/webs";
import "@pnp/sp/lists";
import "@pnp/sp/items";
import "@pnp/sp/batching";
import "@pnp/sp/sites";
import "@pnp/sp/fields";
import "@pnp/sp/attachments";
import "@pnp/sp/site-users/web";
import "@pnp/sp/profiles";
import "@pnp/sp/search";

Get list items. Uses paging.

public async getListItems(listTitle: string, selectFields: Array<string>, expandFields: string = "", filter: string = "", orderBy: string = "Id", ascending: boolean = false, startingIndex: number = 0, top: number = 0, webUrl: string = "", cachingOptions?: ICachingOptions): Promise<any[]> {
	try {
		const web = this.getWeb(webUrl);
		let itemCollection: PagedItemCollection<any> = null;

		try {
			const query = web.lists.getByTitle(listTitle).items
				.filter(filter).select(selectFields.join(","))
				.skip(startingIndex).top(top).expand(expandFields);

			if (this.shouldCache(cachingOptions?.enable))
				query.using(Caching(cachingOptions.props))

			itemCollection = await query.getPaged();

		} catch (e) {
			// silently continue
		}

		if (EntityHelper.isNullOrUndefined(itemCollection))
			return [];

		if (!itemCollection.hasNext) {
			if (orderBy)
				return EntityHelper.copyAndSort(itemCollection.results, orderBy, !ascending);
			else
				return itemCollection.results;
		} else {
			let results: Array<any> = [].concat(itemCollection.results);

			while (itemCollection.hasNext) {
				itemCollection = await itemCollection.getNext();
				results = results.concat(itemCollection.results);
			}

			if (orderBy)
				return EntityHelper.copyAndSort(results, orderBy, !ascending);
			else
				return results
		}
	}
	catch (e) {
		console.error(e);
		return null;
	}
}

Get choice column values

public async getChoiceColumnValues(listTitle: string, columnName: string, webUrl: string = "", cachingOptions?: ICachingOptions): Promise<Array<string>> {
	try {
		const web = this.getWeb(webUrl);
		const query = web.lists.getByTitle(listTitle).fields.getByInternalNameOrTitle(columnName);

		if (this.shouldCache(cachingOptions?.enable))
			query.using(Caching(cachingOptions.props));

		const field = await query();

		// Note: Single type Choice field type is 6, multi-choice field is type 15: "field.FieldTypeKind"
		if (!field || Object.prototype.hasOwnProperty.call(field, "Choices") === false) {
			return [];
		}

		return field.Choices;
	}
	catch (e) {
		console.error(e);
		return null;
	}
}
@juliemturner
Copy link
Collaborator

Yes, we're aware the fix will go out in today's release: #2929

Copy link

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants