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

Add support for caching in Flows #16

Open
jongpie opened this issue Mar 6, 2023 · 4 comments
Open

Add support for caching in Flows #16

jongpie opened this issue Mar 6, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@jongpie
Copy link
Owner

jongpie commented Mar 6, 2023

No description provided.

@jongpie jongpie added the enhancement New feature or request label Mar 6, 2023
@jongpie jongpie self-assigned this Mar 6, 2023
@jefersonchaves
Copy link

Are you considering adding Flow Apex Action(s) to put and get items from the cache to expose a portion of the cache into Flows?

@jongpie
Copy link
Owner Author

jongpie commented Jul 9, 2023

@jefersonchaves yeah, the idea is to add Apex invocable actions that can by used in Flow to put and get cache values. I meant to add details to the description of this issue, but I guess I never did 😅

Since you can have only 1 invocable method per class, and invocable methods don't support generic Object data type, I think it would have to be 2 invocable actions per data type (1 invocable for put, 1 for get). Ideally, it should support retrieving/adding singular and collection values (like String and List<String>)

I haven't spent much time exploring this, but my original thought was to have something like this for each primitive data type:

public class FlowStringCacheAdder {
    public class FlowInput {
        @InvocableVariable(required=true)
        public String cacheKey;
        @InvocableVariable(required=true)
        public String cacheType;
        @InvocableVariable(required=true)
        public String cacheValue;
    }

    public static void execute(List<FlowInput> cacheKeys) {
        for (FlowInput input : inputs) {
            CacheManager.getOrganizationCache().put(input.cacheKey, input.cacheValue);
        }
    }
}

And for retrieving the values...

public class FlowStringCacheGetter {
    public class FlowInput {
        @InvocableVariable(required=true)
        public String cacheKey;
        @InvocableVariable(required=true)
        public String cacheType;
    }

    public static List<String> execute(List<FlowInput> inputs) {
        List<String> cachedValues = new List<String>();
        for (FlowInput input : inputs) {
            CacheManager.getOrganizationCache().get(input.cacheKey);
        }
        return cachedValues;
    }
}

Let me know if you think this pattern/approach makes sense.

@jefersonchaves
Copy link

That is interesting because it may be four classes per Data Type (due to the Flow Apex Action structure):

  • Get String.
  • Put String.
  • Get List<String>.
  • Put List<String>.

This makes me wonder if this is the right path or if we should do it differently: primarily due to Custom Data Types - which can be handy but maybe not so much in Flows. I'm not fond of using JSON serialization to bypass it due to excessive CPU consumption.

Perhaps a top-level class for Get and another for Put with optional variables may work better also because I'm thinking about finding the correct Action on the toolbar.

This way it may end up with two with multiple optional inputs and returns:

  • Put with optional input:
    • String
    • List<String>
    • Decimal
    • List<Decimal
    • SObject
    • List<SObject>
  • Get with optional return:
    • [Same as 'Put' above]
    • Data type to retrieve (e.g. String, or List).

Another option would be to wrap some of it for Flows, but that is what I'm trying to stay away.

@jongpie
Copy link
Owner Author

jongpie commented Aug 16, 2023

@jefersonchaves I agree that having 4 classes per data type is a lot of classes, but it feels like the more intuitive & scalable approach overall. My concerns with the approach of a top-level class for Get and another for Put with optional variables are:

  1. Having optional parameters could lead to more human error when configuring the action - admins might accidentally select the wrong input/output. With separate classes (1 class per data type + cache action), only relevant properties would need to be included (and inputs could be marked as required)
  2. It isn't a scalable design - I want admins/developers to be able to add support for additional data types in their orgs (such as instances of their own Apex classes, etc). With 1 Get and 1 Put class....
    1. Admins/developers could update the Get and Put classes to add the new data types, but that would then prevent them from upgrading to new versions of Nebula Cache Manager's unlocked packages
    2. Admins/developers could create their own Get and Put classes for their own custom data types, but then the UX for people using the Flow actions is inconsistent in their org - they would have to know to use the included Get action for , but use a different action(s) for any custom data types in their orgs. With the approach of 1 class per data type + cache action, orgs that add their own custom classes would provided the same experience in Flow Builder when selecting a caching action

I think there are definitely pros & cons with both options - I'm hoping to build some proof-of-concepts in the coming weeks to see how they compare.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants